在ng-repeat-start和ng-repeat-end中使用作用域
Using scope within an ng-repeat-start and ng-repeat-end
我试图将字符串放在ng重复的名称下面,但当我将它放入时,它并没有显示,好像它只是来自{{}}的正常范围。
另外,当我把它放在一个带有列表的ng-repeat中,它会把整个内容打印得很宽,就像它把每个字母分成列表的每个部分一样,所以这显然是不行的。
我只需要它从对象的名称下打印出重要性级别。
$scope.profileCompare = {
You: {
questionAnswer: [false, true, false, false, false, false],
percent: ['20%', '40%', '60%', '80%', '100%'],
questionImportance: "Unimportant"
},
Pizza: {
questionAnswer: [true, false, false, false, false, false],
percent: ['20%', '40%', '60%', '80%', '100%'],
questionImportance: "Very important"
},
Greenie: {
questionAnswer: [false, true, false, false, true, false],
percent: ['20%', '40%', '60%', '80%', '100%'],
questionImportance: "Important"
}
}
<div ng-repeat-start="(key, value) in profileCompare" style="float: left">{{key}} <br>
<ul class="comparison-list">
<li ng-repeat="importance in value.questionImportance track by $index">
{{importance}}
</li>
</ul>
</div>
<ul ng-repeat-end class="comparison-list" style="float: right">
<li ng-repeat="answerswer in value.questionAnswer track by $index" style="position:relative; " class="fa-li fa" ng-class="{green:answer, red:!answer, 'fa-check-square':answer, 'fa-square':!answer}">
</li>
<br>
<li ng-repeat="percent in value.percent track by $index" style="position:relative; float:right">
{{percent}}
</li>
我不能100%确定我理解你想要什么,但我要做一些假设。
我稍微改变了你的对象,使它被包装在一个数组中,并将"name"推入它自己的属性中。
$scope.profileCompare = [{
name: 'You',
stats: {
questionAnswer: [false, true, false, false, false, false],
percent: ['20%', '40%', '60%', '80%', '100%'],
questionImportance: "Unimportant"
}
}, {
name: 'Pizza',
stats: {
questionAnswer: [true, false, false, false, false, false],
percent: ['20%', '40%', '60%', '80%', '100%'],
questionImportance: "Very important"
}
}, {
name: 'Greenie',
stats: {
questionAnswer: [false, true, false, false, true, false],
percent: ['20%', '40%', '60%', '80%', '100%'],
questionImportance: "Important"
}
}];
下面是你如何在一些无序列表中表示它。再说一次,我不明白你到底想达到什么目的,但我希望这能让你到达你需要去的地方:
<div ng-repeat-start="profile in profileCompare" class="header">{{profile.name}}
</div>
<div>
{{profile.stats.questionImportance}}
</div>
<ul ng-repeat="qanswer in profile.stats.questionAnswer track by $index">
<li>{{qanswer}}</li>
</ul>
<ul ng-repeat="pct in profile.stats.percent track by $index">
<li>{{pct}}</li>
</ul>
<div ng-repeat-end>
<br />
</div>
这里的jfiddle
相关文章:
- 以新模式访问作用域形式ng repeat
- 使用ng repeat中的键值来扩展作用域表达式
- 如何在使用ng repeat时停止传播(或者如何更好地隔离作用域)
- 角度指令作用域绑定在 ng-repeat中不起作用
- 如何在具有隔离作用域的指令中使用 ng-repeat
- 如何使用 ng-repeat引用作用域中的特定变量
- 将作用域变量设置为ng repeat中的ng模型
- AngularJS:ng repeat未在作用域指令内执行
- 在包含的ng-repeat中访问指令的作用域
- AngularJS从外部访问作用域ng-repeat
- 如何修改指令中ng-repeat创建的每个元素的作用域
- 使用ng-click在与ng-repeat相同的标签上使用ng-repeat作用域的参数
- 改变ng-repeat from指令内部的作用域
- 在ng-repeat循环和双向数据绑定之外访问ng-repeat的子作用域
- 在Angular中将父作用域的值传递给ng-repeat循环
- Angularjs的ng-repeat带过滤器作用域对象
- 在ng-repeat中交替使用作用域var而不绑定类
- AngularJS作用域没有在ng-repeat中绑定数据
- $http承诺不更新作用域(ng-hide)
- 删除多个使用数据表不起作用的ng-repeat行