Friday, 1 April 2016

Angular 2 Random Quote Generator, Step 1

I started coding freeCodeCamp's project titled 'Build a Random Quote Machine'.

Here's the first iteration:

// import does not work in Codepen
// using const instead
const {Component, Inject} = ng.core;
const {bootstrap} = ng.platform.browser;
const {HTTP_PROVIDERS, Http, Response} = ng.http;
@Component({
selector: 'my-app',
template: '<h1>{{ quote }}</h1>'
})
class QuoteComponent {
quote: string;
constructor(@Inject(Http) http) {
http.get('http://cfierbin.github.io/assets/data/myQuotes.json')
.subscribe((response: Response) => this.quote = response.text());
}
}
bootstrap(QuoteComponent, [HTTP_PROVIDERS]);
view raw quotesStep1.js hosted with ❤ by GitHub
My textbook for learning Angular 2 is Angular 2 Development with TypeScript, by Yakov Fain and Anton Moiseev.

P.S. Today is April Fool's Day. Stay foolish! (Steve Jobs)

References

No comments: