1
我建立使用MEAN堆棧應用角度2.儘管rxjs適當進口,財產「地圖」上不存在類型「可觀察<Response>」
我知道這個問題已經被問多次在計算器上。我一直在研究這些問題並嘗試不同的建議。對於大多數人來說,導入整個rx/js庫和地圖,或導入:
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
似乎解決了這個問題。我一直在嘗試不同的這種組合,無濟於事。我在我的服務中不斷收到有關.map所有實例的錯誤。我嘗試更新我的全局打印稿,以及我的打字稿版本正在使用的依賴關係。 'ng serve'後我的終端出現錯誤。我認爲這是一個打字稿問題,但我不確定 - 現在導入的observables無法解決它,這個錯誤有點模糊。
的package.json
{
"name": "aether-news",
"version": "0.0.0",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/common": "^2.4.0",
"@angular/compiler": "^2.4.0",
"@angular/core": "^2.4.0",
"@angular/forms": "^2.4.0",
"@angular/http": "^2.4.0",
"@angular/platform-browser": "^2.4.0",
"@angular/platform-browser-dynamic": "^2.4.0",
"@angular/router": "^3.4.0",
"@types/googlemaps": "^3.26.8",
"@types/jquery": "^2.0.43",
"@types/lodash": "^4.14.62",
"@types/underscore": "^1.8.0",
"amcharts3-angular2": "github:amcharts/amcharts3-angular2",
"angular2-google-maps": "^0.17.0",
"core-js": "^2.4.1",
"dotenv": "^4.0.0",
"jquery": "^3.2.1",
"lodash": "^4.17.4",
"ng2-google-charts": "^2.1.0",
"rxjs": "^5.1.0",
"tslint": "^4.4.2",
"typescript": "^2.4.2",
"underscore": "^1.8.3",
"zone.js": "^0.7.6"
},
"devDependencies": {
"@angular/cli": "1.0.0-rc.0",
"@angular/compiler-cli": "^2.4.0",
"@types/jasmine": "2.5.38",
"@types/node": "~6.0.60",
"codelyzer": "~2.0.0",
"jasmine-core": "~2.5.2",
"jasmine-spec-reporter": "~3.2.0",
"karma": "~1.4.1",
"karma-chrome-launcher": "~2.0.0",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^0.2.0",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.0",
"ts-node": "~2.0.0",
"tslint": "~4.4.2",
"typescript": "^2.4.2",
"upgrade": "^1.1.0"
}
}
在我的服務
進口
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
服務代碼
import { Injectable } from '@angular/core';
import { Http, Response, Headers, RequestOptions } from '@angular/http';
import { Router } from '@angular/router';
import { Observable } from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class NewsApiService {
public bingToken: string;
public bbc: any;
public bingWorld: any;
public bingPolitics: any;
public apNews: any;
public googleNews: any;
public economistNews: any;
public nytNews: any;
public wapoNews: any;
public cnnNews: any;
public newsweekNews: any;
public reutersNews: any;
public guardianUkNews: any;
public guardianAuNews: any;
public huffPostNews: any;
public wsjNews: any;
public eventRegistryBBC: any;
public eventRegistryGuardian: any;
public eventRegistryCNN: any;
public eventRegistryWAPO: any;
public eventRegistryReuters: any;
public eventRegistryNYT: any;
public eventRegistryEconomist: any;
public eventRegistryAP: any;
public eventRegistryWSJ: any;
public eventRegistryNewswire: any;
constructor(
private http: Http,
private router: Router
) {}
//EVENT REGISTRY
//BBC
getEventRegistryBBC(){
return this.http.get("http://eventregistry.org/json/article?sourceUri=bbc.co.uk&sourceUri=bbc.com&categoryUri=dmoz%2FSociety%2FPolitics&action=getArticles&articlesSortBy=date&resultType=articles&articlesCount=200&articlesIncludeArticleDuplicateList=true&articlesIncludeArticleCategories=true&articlesIncludeConceptImage=true&articlesIncludeConceptDescription=true&articlesIncludeConceptDetails=true&articlesIncludeConceptTrendingScore=true&articlesIncludeSourceDescription=true&articlesIncludeArticleImage=true&articlesIncludeSourceDetails=true")
.map((res) => {
this.eventRegistryBBC = res.json()
return res.json().articles.results;
})
}
很好奇的人是否都面臨着同樣的問題,即使有rxjs適當進口。感謝你的協助。
你能添加產生這個錯誤的代碼嗎?你在哪裏使用Observable? –
DeborahK
hi @DeborahK,我添加了我的服務代碼。抱歉,該文件相當長 - 我將其縮短爲只有一個API調用。 – sharedev
你見過[這個答案](https://stackoverflow.com/questions/42693265/property-map-does-not-exist-on-type-observableresponse-when-using-angular)? –