Angular 2 ng-model-options =“{updateOn:'change blur'}”

时间:2017-02-23 10:38:51

标签: javascript angularjs angular typescript

我正在使用angular 2,我想在Enter后更改ngModel,在角度1.X中我们可以使用ng-model-options="{updateOn: 'change blur'}",但在角度2中我们该怎么办?

angular 1.x

<input class="form-control value-max" type="text" ng-model="$ctrl.filterData.price_max" ng-model-options="{updateOn: 'change blur'}">

2 个答案:

答案 0 :(得分:7)

从Angular 5开始,它是可能的! 您可以在模板中写下:

<input [(ngModel)]="firstName" [ngModelOptions]="{updateOn: 'blur'}">

了解更多信息: https://next.angular.io/api/forms/NgModel#options

答案 1 :(得分:1)

Angular2不允许您以这种方式修改ngModel的行为。

您可以使用

<input [(ngModel)]="filterData.price_max" 
       (ngModelChange)="doSomething($event)">
相关问题