2016-07-13 6 views
3

ich versuche, eine HTTP-Anfrage mit Winkel 2 (Version: 2.0.0-rc.1, installiert mit CLI) und bekomme diesen Fehler und ich weiß nicht, wo das Problem ist?angular2 http TypeError

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

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

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" 

Vielen Dank für Ihre Hilfe!

Antwort

1

Ich hatte ein ähnliches Problem. Versuchen Sie

npm install --save @angular/http 

Stellen Sie sicher, dass die Version rc.1 in package.json ist.