AngularJS - Why is ng-change called before the model is updated?

前端 未结 1 1303
清歌不尽
清歌不尽 2021-01-04 06:10

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

相关标签:
1条回答
  • 2021-01-04 06:42

    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:

    1. you can define your isolated scope in the directive with the change: '=' definition

    2. 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

    0 讨论(0)
提交回复
热议问题