简体   繁体   English

angular2 http TypeError

[英]angular2 http TypeError

i try to make a http request with angular 2 (version: 2.0.0-rc.1, installed with CLI) and get this error and I don't know how to where the problem is? 我尝试使用角度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

component.ts component.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 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 的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"

Thanks for your help! 谢谢你的帮助!

I had a similar problem. 我遇到了类似的问题。 Try 尝试

npm install --save @angular/http

Ensure that the version is rc.1 in package.json. 确保package.json中的版本为rc.1。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM