Created
December 6, 2015 11:53
-
-
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.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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