0
私はionic2/angular2のフィーリングを得ようとしており、ビューからの変更をコントローラにバインドする方法について固執しています。ビューからの変更をコントローラにバインドする方法を教えてください。
以下のスニペットでは、2つのモーダルセレクトボックスを設定しましたが、どちらもコントローラにモデル変更を戻すことはありません。デフォルトにリロードします。どのように変数を返すことができますか?
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(答えに基づいて更新):
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;
})
}
}
優れたポイントは、機能シグニチャのものを必要としません。 –
私の編集とプランナーを参照してください –
これはそれでした。ありがとう! –