在AngularJS $父更换 [英] Replacement of $parent in AngularJS

查看:134
本文介绍了在AngularJS $父更换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

引用我刚才的<一个href=\"http://stackoverflow.com/questions/18258910/directive-working-in-one-controller-and-not-in-another/18259197\">post,为什么使用$父code在这里
&LT; FM评级NG模型=$ parent.restaurant.rating只读=真&GT;&LT; / FM评级&GT; 。全code是这里

Referencing my earlier post, why is the code using $parent here <fm-rating ng-model="$parent.restaurant.rating" readonly="true"></fm-rating>. The full code is here.

我一直在阅读它提到要避免使用$父的博客,因此,我的问题。有没有更好的方式来写code?或者是有没有办法,因为在主页上的过滤器需要影响的结果在这个截图中的应用

I have been reading blogs which mention to avoid using $parent, hence my question. Is there a better way to write that code? Or is there no way, since the filters on the home page need to affect the results as seen in this screenshot of the app

推荐答案

FM评级声明一个孤立的范围,所看到的这里,这意味着它不使用原型继承来获得访问父属性

fm-rating declares an isolated scope, as seen here, which means it does not use prototypical inheritance to get access to the parent properties.

当你想有一个范围,你可以使用任何名字,而不必担心覆盖parent属性,这非常有用。这种隔离的突围的唯一方法就是使用 $父,上指范围的父隔离范围的财产!

This is useful when you want a scope in which you can use any names without worrying about overriding a parent property. The only way to "break out" of this isolation is to use $parent, a property on the isolated scope that refers to the parent of the scope!

有关详细信息,搜索指令的的文档中的隔离。

For more information, search for "isolate" in the documentation of directives.

这篇关于在AngularJS $父更换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆