I'm trying to get a feel for ionic2/angular2 and have gotten stuck on how to bind a change from the view back to the controller.
In the snippet below, I set up two modal select boxes, but neither propagates the model change back to the controller-- it reloads the defaults. How can I pass the variables back?
HTML:
<ion-select [(ngModel)]="base" (ngModelChange)="loadCurrencyExchange()">
<ion-option *ngFor="let b of supportedCurrencies" value="{{b}}">
{{b}}
</ion-option>
</ion-select> to
<ion-select [(ngModel)]="symbols" (ngModelChange)="loadCurrencyExchange()" multiple="true">
<ion-option *ngFor="let s of supportedCurrencies" value="{{s}}">
{{s}}
</ion-option>
</ion-select>
JS (updated based upon answers):
export class HomePage {
public currenciesLoaded: any;
public supportedCurrencies: string[];
@Output() public exchangeRates: any;
public dataLoaded: boolean;
@Input() base: string = 'USD';
@Input() symbols: string[] = ['EUR','RUB'];
constructor(public CurrencyService: CurrencyService) {
var base: string = this.base;
var symbols: string[] = this.symbols;
this.loadCurrencyList();
this.loadCurrencyExchange();
}
loadCurrencyList(){
this.supportedCurrencies =this.CurrencyService.loadCurrencySymbols();
}
loadCurrencyExchange(){
this.CurrencyService.loadCurrencies(this.base, this.symbols)
.then(data => {
console.log(this.base + ' to ' + this.symbols.join(','));
this.exchangeRates = data;
this.currenciesLoaded = Object.keys(data.rates);
this.dataLoaded = true;
})
}
}