0
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { RestfulComponent } from '/app/rest/app.restful.component.ts';
import { HttpModule } from '@angular/http';
@NgModule({
imports: [
BrowserModule,
HttpModule
],
declarations: [
RestfulComponent
],
bootstrap: [ RestfulComponent ]
})
export class AppModule { }
app.restful.module.tsangular2無法解決所有參數AppComponent:(?)
import { Component } from '@angular/core';
import { RestfulService } from '/app/rest/restful/restfull.service.ts';
import {Http} from '@angular/http';
import { Observable } from 'rxjs';
@Component({
selector: 'my-app',
template: `
<button (click)="onTestGet()">GET TEST</button><br>
<p>Output: {{getData}}</p>
`,
providers: [RestfulService]
})
export class RestfulComponent {
getData: string;
postData: string;
//
constructor (private _http: Http){}
onTestGet(){
this._restfulService.getCurrentTime().subscribe(
data => this.getData = JSON.stringify(data),
error => alert(error),
() => console.log("end")
);
}
}
app.restful.component.ts
import {Injectable} from '@angular/core';
import {Http} from '@angular/http';
import {Headers} from '@angular/http';
import 'rxjs/add/operator/map'
@Injectable()
export class RestfulService {
constructor (private _http: Http){}
getCurrentTime(){
return this._http.get('http://date.jsontest.com').map(res => res.json());
}
}
restful.service.ts
[的test.html2
我沒有關於角多少知識。如果您在缺少任何信息或文件的情況下,我在這裏添加。
我會把他們產生下面的錯誤改變的代碼:
,我應該怎麼辦?構造方法內