AngularJS - 为什么叫NG-变化模型更新过吗? [英] AngularJS - Why is ng-change called before the model is updated?
问题描述
请参阅以下plnkr: http://plnkr.co/edit/KZwIBX?p=$p $ PVIEW
第一标准选择按预期工作(至少据我预期/预期),这意味着模型更新后的NG-改叫。但是,当我创建一个具有隔离范围,它似乎是我的模型更新之前NG-变化被称为指令。显然,也有一些是我误解。
您可以在变更指令定义范围隔离
您可以使用它,因为它是,但调用带有参数的父对象引用的功能。
对于这里的第二个例子是一个很好的解释:
<一href=\"http://www.thinkster.io/pick/oEo8ZAXv27/angularjs-isolate-scope\">http://www.thinkster.io/pick/oEo8ZAXv27/angularjs-isolate-scope
Please see the following plnkr: http://plnkr.co/edit/KZwIBX?p=preview
The first standard select works as expected(at least as far as I expected/anticipated), meaning that ng-change is called after the model is updated. But when I create a directive that has an isolate scope it would seem that ng-change is called before my model is updated. Obviously there is something I am misunderstanding.
Situation very similar to AngularJS scope updated after ng-change
The problem with the example in the plnkr is that you are passing the change function, to the isolate scope as a binding to the parent scope by using change : '&'. By using the & the function will be evaluated as an expression in the context of the parent and it will be evaluated before model changed (if there is no binding to the model as a parameter)
There can be two ways to change the example in order to work:
you can define your isolated scope in the directive with the change: '=' definition
you can use it as it is but call the parent referenced function with a parameter. For the second example here is a great explanation: http://www.thinkster.io/pick/oEo8ZAXv27/angularjs-isolate-scope
这篇关于AngularJS - 为什么叫NG-变化模型更新过吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!