Created
October 1, 2017 02:37
-
-
Save freshcutdevelopment/3c4d325703ce5c4dc5df900ec4749ff6 to your computer and use it in GitHub Desktop.
Country picker view-model
This file contains hidden or 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 {HttpClient} from 'aurelia-fetch-client'; | |
import {bindable} from 'aurelia-framework'; | |
export class CountryPicker{ | |
@bindable country; | |
constructor(){ | |
this.selected = {"name" : 'Australia', "code" : 'AU'}; | |
this.templateUrl = 'templates/country-template.html'; | |
} | |
getCountries(countryName){ | |
let client = new HttpClient(); | |
return client.fetch('countries.json') | |
.then(response => response.json()) | |
.then(countries => { | |
if(!countryName) return countries; | |
return countries.filter(c => c.name.toUpperCase().indexOf(countryName.toUpperCase() !== -1)); | |
}); | |
} | |
countryChanged(evt){ | |
if(!evt.target) return; | |
this.country = evt.target.value; | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment