角 - 射击时NG-NG模式变化不会改变 [英] Angular - ng-change not firing when ng-model is changed

查看:208
本文介绍了角 - 射击时NG-NG模式变化不会改变的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

的输入是:

<input type="text" ng-model="repair.test"  ng-change="action()" />

动作()是,当我手动键入和改变输入执行。然而,如果我通过一些其他的功能改变repair.test值编程,它不火NG-变化的行动。我已阅读角的教程和它可能是预期的行为。

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

当值的变化是从模型来这位前pression不计算。 &LT; - 我需要这一点。
我如何可以触发控制器的动作,当模型以任何方式改变? (打字输入或通过任何其它功能)

"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)

感谢您的帮助。

编辑:

该模型的价值实际上是的形式。$有效,它有它的周围(我认为)自己的表单控制器,这就是为什么我用动作功能试用传递值到父控制器。因此, $范围。$看此刻不起作用,只有当它被初始化。

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-NG模式变化不会改变的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆