【问题标题】:angular2 http TypeErrorangular2 http类型错误
【发布时间】:2016-07-13 15:55:23
【问题描述】:

我尝试使用 angular 2(版本:2.0.0-rc.1,使用 CLI 安装)发出 http 请求并收到此错误,但我不知道问题出在哪里?

browser_adapter.js:77ORIGINAL EXCEPTION: TypeError: platform_browser_1.__platform_browser_private__.getDOM(...).getCookie is not a function

组件.ts

    import { Component } from '@angular/core';
import { Http } from '@angular/http';
import 'rxjs/Rx';

@Component({
    moduleId: module.id,
    selector: 'my-second-element',
    templateUrl: 'my-second-test.component.html',
    providers:[]
})


export class MySecondTestAppComponent {
    constructor(private _http: Http) {
        this.print_data();
    }

    print_data() {
        this.getData().subscribe(
            data => console.log(JSON.stringify(data)),
            error => console.log(error),
            () => console.log("finish")
        )
    }

    getData() {
        return this._http.get('http://date.jsontest.com');
    }

}

main.ts

import { bootstrap } from '@angular/platform-browser-dynamic';
import { enableProdMode } from '@angular/core';
import { HTTP_PROVIDERS } from '@angular/http';

import { MySecondTestAppComponent, environment } from './app/';

if (environment.production) {
  enableProdMode();
}

bootstrap( MySecondTestAppComponent, [HTTP_PROVIDERS]);

package.json

  "private": true,
  "dependencies": {
    "@angular/common": "2.0.0-rc.1",
    "@angular/compiler": "2.0.0-rc.1",
    "@angular/core": "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",
    "es6-shim": "^0.35.0",
    "reflect-metadata": "0.1.3",
    "rxjs": "5.0.0-beta.6",
    "systemjs": "0.19.26",
    "zone.js": "^0.6.12"

感谢您的帮助!

【问题讨论】:

    标签: angularjs typescript angular angular2-http


    【解决方案1】:

    我遇到了类似的问题。试试

    npm install --save @angular/http
    

    确保 package.json 中的版本为 rc.1。

    【讨论】:

      猜你喜欢
      • 2017-12-12
      • 2016-03-31
      • 2017-05-23
      • 2016-08-06
      • 1970-01-01
      • 2016-11-01
      • 2016-04-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多