替换 AngularJS 中的 $parent [英] Replacement of $parent in AngularJS

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

问题描述

参考我之前的帖子,为什么这里使用 $parent 的代码<fm-rating ng-model="$parent.restaurant.rating" readonly="true"></fm-rating>.完整代码在这里.

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.

我一直在阅读提到避免使用 $parent 的博客,因此我提出了问题.有没有更好的方法来编写该代码?或者没有办法,因为主页上的过滤器需要影响结果,如 应用程序

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-rating 声明了一个隔离的作用域,如这里,这意味着它不使用原型继承来访问父属性.

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!

有关更多信息,请在指令文档中搜索isolate".

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

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

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