本文介绍了以编程方式更改模型时,ngChange不起作用?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在中说 ngChange 不会触发:如果以编程方式更改模型而不是通过更改输入值。

It says in the docs that ngChange will not fire: "if the model is changed programmatically and not by a change to the input value".

这是否意味着如果您永远以编程方式更改模型,你不能使用 ngChange

Does this mean that if you ever change the model programmatically, you can't use ngChange?

或者它意味着您不能使用 ngChange 如果:

Or does it mean that you can't use ngChange if:

1)您可以通过编程方式更改模型

1) You change the model programmatically

AND

2)您无法通过输入字段更改模型

2) You're unable to change the model via the input field

推荐答案

这只是意味着如果使用javascript来更改模型,则不会评估ngChange表达式。如果你想要触发ngChange,你需要以编程方式调用类似于以下内容的表达式:

It just means that the ngChange expression won't be evaluated if javascript is used to change the model. If you wanted ngChange to fire you would need to programmatically call the expression similar to the following:

<input type="checkbox" ng-model="confirmed" ng-change="change()" id="ng-change-example1" />

如果你想激活它,你需要手动调用更改功能:

You would need to manually call the change function if you wanted it to fire:

$scope.confirmed = 'test';
$scope.change();

这篇关于以编程方式更改模型时,ngChange不起作用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-13 01:42