//our root app component
import {Component, NgModule} from '@angular/core'
import {BrowserModule} from '@angular/platform-browser'
import {HttpModule} from '@angular/http'
import {Http} from '@angular/http'
@Component({
selector: 'my-app',
template: `
Angular {{appType}} app
| Request status |
{{requestStatus}} |
| Request url |
{{requestUrl}} |
| Response code |
{{responseCode}} |
| Response data |
{{responseData | json}} |
`,
})
export class App {
requestStatus = "not started";
requestUrl = "/api/sample.json";
responseCode = "";
responseData = "";
appType = "";
constructor(
private http: Http
) {
this.getData();
}
getData() {
this.requestStatus = 'in progress';
this.http.request(this.requestUrl, {method: 'get'}).subscribe((data) => {
this.requestStatus = 'done';
this.responseCode = data.status;
this.responseData = data.json();
this.appType = this.responseData.response;
}, (data) => {
this.requestStatus = 'done';
this.responseCode = data.status;
this.responseData = data.json();
this.appType = this.responseData.response;
});
}
}
@NgModule({
imports: [BrowserModule, HttpModule],
declarations: [App],
bootstrap: [App]
})
export class AppModule {
}