Rob*_*Rob 5 javascript input typescript ngmodel angular
我有一个数字类型输入,当我尝试使用onChange事件更改值时,它不起作用.
我已尝试相同的文本输入,它的工作完美.
<input
type="number"
[(ngModel)]="element.value"
(change)="onChange($event)"
>
export class NumFieldComponent {
@Input() index;
@Input() element; //element.value = 0
onChange($event){
var confirm = confirm("Are you sure about this?")
if(confirm){
//True, accept the value
} else {
this.element.value = 0;
//Failed, set the input back to 0
}
}
}
Run Code Online (Sandbox Code Playgroud)
我是Angular2的新手,所以我在这里缺少什么?
PS.我看到类似的问题,输入采取bool
没有尝试过,但可能有用
export class NumFieldComponent {
@Input() index;
@Input() element; //element.value = 0
constructor(cdRef:ChangeDetectorRef) {}
onChange($event){
var confirm = confirm("Are you sure about this?")
if(confirm){
//True, accept the value
} else {
this.element.value = 0;
this.cdRef.detectChanges(); // <<<=== added
//Failed, set the input back to 0
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8315 次 |
| 最近记录: |