本文介绍了可观察到的角响应中不存在特性图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Visual Studio 2015应用程序中使用打字稿来构建angular 2应用程序.我正在使用角度释放候选1.

I am trying to build an angular 2 application using typescript in visual studio 2015 application. I am using angular release candidate 1.

我创建了一个risk.service组件,该组件将向我的视图提供数据.尝试使用可观察的.但是我在Visual Studio编辑器中收到以下错误消息

I have created a risk.service component which will provide data to my view. Trying to use observable. However I am getting the following error message in my visual studio editor

可观察到的响应不存在属性图

property map does not exist on observable response

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

(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

{
  "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": {}
}

推荐答案

您遇到的问题实际上与TypeScript VS加载项和Intellisense(尤其不是Angular2)有关.这是一个已知问题,已修复,将包含在下一版本中.

The problem you are experiencing is actually related to the TypeScript VS add-in and Intellisense not specifically Angular2. It's a known issue that has been patched and will be included in the next release.

替换文件:C:\ Program Files(x86)\ Microsoft Visual Studio 14.0 \ Common7 \ IDE \ CommonExtensions \ Microsoft \ TypeScript \ typescriptServices.js

Replace the file: C:\Program Files (x86)\Microsoft Visual Studio 14.0\Common7\IDE\CommonExtensions\Microsoft\TypeScript\typescriptServices.js

使用下面的文件.备份后: https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js

With the file below. After making a backup: https://raw.githubusercontent.com/Microsoft/TypeScript/Fix8518/lib/typescriptServices.js

从技术上讲,这是(请参见Eric Weiss的答案):

This is technically a duplicate of question (See Eric Weiss answer):

GitHub问题

这篇关于可观察到的角响应中不存在特性图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-01 20:31