问题描述
我正在使用onchange将输入范围的值保存到firebase中,但是我有一个错误,谁未定义我的函数.
i'm using onchange to save the value of my input range into firebase , but i have an error who say that my function is not defined.
这是我的职责
saverange(){
this.Platform.ready().then(() => {
this.rootRef.child("users").child(this.UserID).child('range').set(this.range)
})
}
这是我的html
<ion-item>
<ion-row>
<ion-col>Rayon <span favorite><strong> {{range}} km</strong></span></ion-col>
<ion-col><input type="range" name="points" min="0" max="40" [(ngModel)]="range" onchange="saverange()"></ion-col>
</ion-row>
</ion-item>
如果存在onchange,则等于angular的onchange.谢谢
what is the equivalent of onchange in angular , if one exist.thank you
推荐答案
由于change
位于标准DOM事件列表上,因此我们可以使用它:
Since change
is on the list of standard DOM events, we can use it:
(change)="saverange()"
在您的特定情况下,由于您使用的是NgModel,因此您可以这样拆分双向绑定:
In your particular case, since you're using NgModel, you could break up the two-way binding like this instead:
[ngModel]="range" (ngModelChange)="saverange($event)"
然后
saverange(newValue) {
this.range = newValue;
this.Platform.ready().then(() => {
this.rootRef.child("users").child(this.UserID).child('range').set(this.range)
})
}
但是,通过这种方法,每次击键都会调用saverange()
,因此最好使用(change)
.
However, with this approach saverange()
is called with every keystroke, so you're probably better off using (change)
.
这篇关于与angular2中的onchange等效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!