2016-04-28 7 views
0

私は別の問題を抱えています。 ローカルサーバーにAPIがあり、通信したいと思います。 しかし、私がするとき404 angle2/httpをapiにリクエスト

import {Http, Response} from 'angular2/http'; or 
import { HTTP_PROVIDERS } from 'angular2/http'; or 
import {HTTP_BINDINGS} from 'angular2/http'; or 
import {Http, Response} from 'angular2/http'; 

私は間違いを見つけましたか? "404 GET/angular2/http"をコンソールに表示します。ここで

は私toolservice.tsです:

import {Injectable} from 'angular2/core'; 
import {Http, Response} from 'angular2/http'; 
import {Tool} from './tool'; 
import {BackendService} from './backend.service'; 

@Injectable() 
export class ToolService { 
constructor( 
    private _backend: BackendService /*,http: Http*/){ } 

    private _tools:Tool[] = []; 

    getTools() { 
    this._backend.getAll(Tool).then((tools:Tool[]) => { 
     this._tools.push(...tools); // fill cache 
    }); 
    return this._tools; } 
    /*launchtool(){ 
    alert("I asked to launch your tool..."); 
    http.get("http://localhost:8080/"); 
    //this.http.get("http://localhost:8080/"); 
    //$http.get("http://localhost:8080/"); 
    }*/ 
} 

私がコメントを解除した場合、「プライベート_backend:BackendService/、民間のhttp:のHttp /){}」 を私は角を見つけることができないエラー原因を得ましたhttp。

私は何かを見逃しましたか?私はnpmの-g httpとhttp-requestをインストールしようとしましたが、それは無効です。

+0

誰かが私を助けコンポーネントです。私はメインのhtmlファイルであるangular2/httpをインポートするのを忘れてしまった。 http://stackoverflow.com/questions/34748257/angular-2-gives-systemjs-cannot-find-angular2-http-module – Ryusekai

答えて

0

これはサービスです。ここで

import { Injectable } from 'angular2/core'; 
import { Http, Response } from 'angular2/http'; 
import 'rxjs/Rx'; 
import { Observable } from 'rxjs/Observable'; 

@Injectable() 
export class BackendService { 
    constructor(private _http: Http) {} 
getAll():Observable<any> { 
return this._http.get('http://localhost:8080/') 
.map(res => res.json()); 
}; 

import { BackendService } from './backend.service'; 
constructor(private backendservice: BackendService) { } 
data: any[]; 

get(): void { 
this.backendservice.getAll().subscribe(data => this.data = data, 
error => console.log(error)); 
}