gpt4 book ai didi

angularjs - 为什么 ng-if 脱离作用域?

转载 作者:行者123 更新时间:2023-12-04 22:12:25 25 4
gpt4 key购买 nike

ng-if 是从作用域中分离输入吗?或者我只是做错了什么?
使用时:

<input ng-if="1===1" ng-model="name">

输入的变化不影响范围。尝试删除 ng-if 和 walla!
那是什么?

attached pluncker

最佳答案

ng-if 创建一个新的子作用域,因此您在子作用域中编辑模型而不是原始作用域。如果您将其更改为 $parent.name,它就可以正常工作。

以下是 Angular 团队的一名成员的理由:

The reason why ng-switch creates a new scope, is that scope is used for memory management.

When the switch branch is removed we need to remove all of the bindings as well as all of the click listeners. This is all done through scope.

To put it differently whenever DOM structure changes, a new scope needs to be created, so that we can properly clean up after ourselves.



https://groups.google.com/forum/#!searchin/angular/why $20does$20ng-switch/angular/n_PlBtwemJg/kk6me3JdE88J

关于angularjs - 为什么 ng-if 脱离作用域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24750736/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com