通过父范围值成角NG-repeat循环 [英] Pass parent scope value into ng-repeat loop in Angular

查看:143
本文介绍了通过父范围值成角NG-repeat循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这应该是一个非常简单的问题,但我已经找到了解决方法是复杂的。我通过在模板中使用NG重复对象的数组循环如下:

This should be an extremely simple question, but all of the workarounds I've found are complex. I'm looping through an array of objects in using ng-repeat in a template as follows:

<div class="row-fluid" ng-repeat="message in messages.current|filter:'draft'"> 
    {{ message.subject }} ... {{ campaign.name }} ...
</div>

由于NG重复创建一个新的范围,从控制器的活动的对象似乎并不被accessable。 (从我的阵列中添加运动物体每个项目除外)获得该值有什么办法?

Since the ng-repeat creates a new scope, the 'campaign' object from the controller doesn't seem to be accessable. Is there any way (aside from adding the campaign object to every item in my array) of getting that value?

先谢谢了。

推荐答案

您可以通过使用$父访问父范围

You can access the parent scope by using $parent

<div class="row-fluid" ng-repeat="message in messages.current|filter:'draft'"> 
    {{ message.subject }} ... {{ $parent.campaign.name }} ...
</div>

这篇关于通过父范围值成角NG-repeat循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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