[英]Angular - Removing two way binding on NgModel?
how do I remove two way binding with [(ngModel)] in angular?如何在角度中删除与 [(ngModel)] 的双向绑定?
I want a seperate handler for setting the value, and another for changing it.我想要一个单独的处理程序来设置值,另一个处理程序用于更改它。 So I can have side-effects
所以我可以有副作用
eg例如
<input [(ngModel)]="selectedEscrowOffering" [ngbTypeahead]="search" [resultFormatter]="escrowFormatter">
in Vue, models were considered syntatic sugar.在 Vue 中,模型被认为是语法糖。
Could I seperate out the two way into a directive and onChangeHandler?我可以将这两种方式分成指令和 onChangeHandler 吗?
<input [value]="selectedEscrowOffering" (change)="someFunctionName($event)" [ngbTypeahead]="search" [resultFormatter]="escrowFormatter">
它与 vue 非常相似,将@Output
和@Input
分开如下:
<input (ngModelChange)="someFunctionName($event)" [ngModel]="mymodel">
Related to the other answer by KLTR, this is how I got it to work:与 KLTR 的另一个答案相关,这就是我让它工作的方式:
This two way binding model:这两种方式绑定模型:
<input [(ngModel)]="selectedEscrowOffering"
can be broken down into the following:可以分为以下几类:
<input [ngModel]="selectedEscrowOffering" (ngModelChange)="onChangeEscrowDropdown($event)>
On the typescript side, add the function that sets it.在打字稿方面,添加设置它的函数。 I had it on a typeahead, and it looked for an elements in the array of objects to match it
我把它放在预先输入的地方,它在对象数组中寻找一个元素来匹配它
onChangeEscrowDropdown($event){
if(typeof $event ==="object"){
this.selectedEscrowOffering = $event
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.