Skip to content

Instantly share code, notes, and snippets.

@molcik
Created September 22, 2017 07:12
Show Gist options
  • Save molcik/4ba97103d56b2467dc45d4656c846c72 to your computer and use it in GitHub Desktop.
Save molcik/4ba97103d56b2467dc45d4656c846c72 to your computer and use it in GitHub Desktop.
app.ts
import {Component, NgModule, VERSION} from '@angular/core'
import {Http} from '@angular/http'// DON'T FORGOT TO IMPORT HTTP
import {BrowserModule} from '@angular/platform-browser'
import {HttpModule} from '@angular/http'; // DON'T FORGOT TO IMPORT HTTPMODULE
@Component({
selector: 'my-app',
template:
`<div>
<h2>Response from server: {{greeting}}</h2>
</div>`
})
export class App {
greeting:string;
constructor(protected http: Http) {
this.requestGreeting()
}
requestGreeting() {
this.http.get("https://private-8ace8-helloworld409.apiary-mock.com/greeting").subscribe(res => {
this.greeting = res.json().data;
})
}
}
@NgModule({
imports: [ BrowserModule, HttpModule ], // DON'T FORGOT TO IMPORT HTTPMODULE
declarations: [ App ],
bootstrap: [ App ]
})
export class AppModule {}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment