[英]property map does not exist on observable response in angular
I am trying to build an angular 2 application using typescript in visual studio 2015 application. 我正在尝试使用visual studio 2015应用程序中的typescript构建一个角度2应用程序。 I am using angular release candidate 1. 我正在使用角度释放候选人1。
I have created a risk.service component which will provide data to my view. 我创建了一个risk.service组件,它将为我的视图提供数据。 Trying to use observable. 试图使用可观察的。 However I am getting the following error message in my visual studio editor 但是,我在Visual Studio编辑器中收到以下错误消息
property map does not exist on observable response 属性映射在可观察的响应中不存在
risk.service.ts risk.service.ts
import { Injectable } from '@angular/core';
import { IRisk } from './risk';
import { Http, Response } from '@angular/http';
import 'rxjs/Rx'
import {Observable} from 'rxjs/Observable';
import 'rxjs/add/operator/map';
@Injectable()
export class RiskService {
private _riskUrl = 'www.MyService.com/api/risks';
constructor(private _http: Http) { }
getRisks(): Observable<IRisk[]> {
return this._http.get(this._riskUrl)
.map((response: Response) => <IRisk[]>response.json());
}
}
Systemjs.config.js Systemjs.config.js
(function (global) {
// map tells the System loader where to look for things
var map = {
'app': 'app', // 'dist',
'rxjs': 'node_modules/rxjs',
'angular2-in-memory-web-api': 'node_modules/angular2-in-memory-web-api',
'@angular': 'node_modules/@angular',
'primeng': 'node_modules/primeng'
};
// packages tells the System loader how to load when no filename and/or no extension
var packages = {
'app': { main: 'main.js', defaultExtension: 'js' },
'rxjs': { defaultExtension: 'js' },
'angular2-in-memory-web-api': { defaultExtension: 'js' },
'primeng': { defaultExtension: 'js' }
};
var packageNames = [
'@angular/common',
'@angular/compiler',
'@angular/core',
'@angular/http',
'@angular/platform-browser',
'@angular/platform-browser-dynamic',
'@angular/router',
'@angular/testing',
'@angular/upgrade',
'@angular/router-deprecated'
];
// add package entries for angular packages in the form '@angular/common': { main: 'index.js', defaultExtension: 'js' }
packageNames.forEach(function (pkgName) {
packages[pkgName] = { main: 'index.js', defaultExtension: 'js' };
});
var config = {
map: map,
packages: packages
}
// filterSystemConfig - index.html's chance to modify config before we register it.
if (global.filterSystemConfig) { global.filterSystemConfig(config); }
System.config(config);
})(this);
Package.json 的package.json
{
"name": "product-management",
"version": "1.0.0",
"author": "Deborah Kurata",
"description": "Package for the Acme Product Management sample application",
"scripts": {
"start": "concurrently \"npm run tsc:w\" \"npm run lite\" ",
"tsc": "tsc",
"tsc:w": "tsc -w",
"lite": "lite-server",
"typings": "typings",
"postinstall": "typings install"
},
"license": "ISC",
"dependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",
"es6-shim": "^0.35.0",
"primeng": "^1.0.0-beta.6",
"primeui": "^4.1.11",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.8",
"systemjs": "0.19.26",
"zone.js": "^0.6.12"
},
"devDependencies": {
"angular-cli": "^1.0.0-beta.0",
"clang-format": "^1.0.35",
"codelyzer": "0.0.14",
"ember-cli-inject-live-reload": "^1.4.0",
"es6-promise": "3.2.1",
"jasmine-core": "^2.4.1",
"jasmine-spec-reporter": "^2.4.0",
"karma": "^0.13.15",
"karma-chrome-launcher": "^0.2.3",
"karma-jasmine": "^0.3.8",
"protractor": "^3.3.0",
"ts-node": "^0.5.5",
"tslint": "^3.6.0",
"typescript": "^1.8.10",
"typings": "^0.8.1"
},
"repository": {}
}
The problem you are experiencing is actually related to the TypeScript VS add-in and Intellisense not specifically Angular2. 您遇到的问题实际上与TypeScript VS加载项和Intellisense有关,而不是Angular2。 It's a known issue that has been patched and will be included in the next release. 这是一个已修补的已知问题,将包含在下一个版本中。
Replace the file: C:\\Program Files (x86)\\Microsoft Visual Studio 14.0\\Common7\\IDE\\CommonExtensions\\Microsoft\\TypeScript\\typescriptServices.js 替换文件:C:\\ Program Files(x86)\\ Microsoft Visual Studio 14.0 \\ Common7 \\ IDE \\ CommonExtensions \\ Microsoft \\ TypeScript \\ typescriptServices.js
With the file below. 使用下面的文件。 After making a backup: https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js 进行备份后: https : //raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js
This is technically a duplicate of question (See Eric Weiss answer): 这在技术上是问题的重复(参见Eric Weiss回答):
I think that you could try to use the 5.0.0-beta.6 version of Rxjs: 我认为您可以尝试使用5.0x-beta.6版本的Rxjs:
"dependencies": {
"@angular/common": "2.0.0-rc.1",
"@angular/compiler": "2.0.0-rc.1",
"@angular/core": "2.0.0-rc.1",
"@angular/http": "2.0.0-rc.1",
"@angular/platform-browser": "2.0.0-rc.1",
"@angular/platform-browser-dynamic": "2.0.0-rc.1",
"@angular/router": "2.0.0-rc.1",
"@angular/router-deprecated": "2.0.0-rc.1",
"es6-shim": "^0.35.0",
"primeng": "^1.0.0-beta.6",
"primeui": "^4.1.11",
"reflect-metadata": "0.1.3",
"rxjs": "5.0.0-beta.6", // <-----
"systemjs": "0.19.26",
"zone.js": "^0.6.12"
},
as suggested in the "5min quickstart" doc on the angular.io website. 正如angular.io网站上的“5min quickstart”文档所述。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.