Angular的作用域Scope理解

来源:互联网 发布:田岛绣花软件9.0 编辑:程序博客网 时间:2024/05/19 11:47

要点之一:
父Scope里的基本类型的属性,子Scope创建时会复制它的值,新创建同名新属性,因此,在子Scope里改变属性值,不会影响父Scope里的属性值。

解决办法:

If you really want/need to use a primitive, there are two workarounds:

1.
Use $parent.parentScopeProperty in the child scope. This will prevent
the child scope from creating its own property.
2.
Define a function on the parent scope, and call it from the child, passing the primitive value up to the parent (not always possible)

https://github.com/angular/angular.js/wiki/Understanding-Scopes
有一篇中文也很好
http://xiaoyu2er.github.io/2016/01/23/angular-scope-in-depth/

0 0
原创粉丝点击