Skip to content

Instantly share code, notes, and snippets.

@ovrmrw
Created December 6, 2015 11:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ovrmrw/cd1814314f7bbe635f8b to your computer and use it in GitHub Desktop.
Save ovrmrw/cd1814314f7bbe635f8b to your computer and use it in GitHub Desktop.
Angular2 Http module runs correctly on alpha.47 but it's failing on alpha.48.
import {Component} from 'angular2/angular2'
import {Http, Response, HTTP_PROVIDERS} from 'angular2/http'
import _ from 'lodash'
@Component({
selector: 'my-page1',
template: `
<ul>
<li *ng-for="#card of cards">{{card.title}}</li>
</ul>
`,
providers: [HTTP_PROVIDERS]
})
export class Page1 {
cards: Card[] = [];
constructor(public http: Http) {
}
loadCards(searchWord: string = '') {
(async() => {
let cards = await this.http.get('/cards.json')
.map((res:Response) => res.json() as Card[])
.toPromise(Promise);
if (searchWord) {
const words = _.words(searchWord);
words.forEach(word => {
cards = _.filter(cards, card => {
return card.title.indexOf(word) > -1 || card.body.indexOf(word) > -1;
});
});
}
this.cards = cards;
})();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment