ng型改变时角度变化不发射 [英] Angular - ng-change not firing when ng-model is changed
问题描述
输入如下:
<input type="text" ng-model="repair.test" ng-change="action()" />
当我执行了 action()
手动输入并更改输入。但是,如果我通过一些其他功能以编程方式更改了repair.test值,则不会触发ng-change的动作。我已经阅读了角度教程,这可能是预期的行为。
The action()
is executed when I manually type and change the input. However if I change the repair.test value by some other function programmatically, it doesnt fire the ng-change's action. I have read the angular tutorial and it's probably the expected behavior.
https://docs.angularjs.org/api/ng/directive/ngChange
当值更改即将到来时,不会对表达式进行评估从模型。 - 我也需要这个。
当模型以任何方式改变时,我如何在控制器中启动一个动作? (输入输入或任何其他功能)
"The expression is not evaluated when the value change is coming from the model." <- I need this too. How can I fire an action in controller, when the model changes in any way? (typing in input or by any other function)
感谢您的帮助。
编辑:
模型值实际上是表单$ valid
,它有它自己的Form控制器(我认为),那个是为什么我使用action函数来尝试将值传递给父控制器。所以 $ scope。$ watch
此时不起作用,只有当它被初始化时。
The model value is actually the form.$valid
, which has it's own Form controller around it (I think), that is why I used the action function to try to pass the value to the parent controller. So $scope.$watch
at the moment doesn't work, only when it is initialised.
推荐答案
ngChange 只是为了输入,如果你想听这个模型做这样的
ngChange is just for the input, if you want to listen the model do like this
$scope.$watch('repair.test', function(newvalue,oldvalue) {
});
这篇关于ng型改变时角度变化不发射的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!