Why does two way binding sometimes work without using a dot in Angular?

99封情书 提交于 2019-12-06 03:15:10
Mark Rajcok

If your directive creates an isolate scope (and there are no intermediate scopes), and it uses = for two-way databinding, you don't need to use object properties – i.e., you don't need a "dot" to get it to work.

In Fiddle 1 and 2, ng-repeat is creating an intermediate (child) scope that prototypically inherits from the MyCtrl scope. In this case, you need to use object properties.

The Fiddle3 makes sense since it tries to hide itself and all variables are in its own isolated scope.

It will be more comparable to Fiddle1 if you want to implement something like when click on X, trigger the Toggle button to hide sample control. Because in Fiddle1 you actually wanted to figure out how to modify the value outside the isolated scope, rather than inside the scope created by the directive.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!