在ng-repeat-start和ng-repeat-end中使用作用域

Using scope within an ng-repeat-start and ng-repeat-end

本文关键字:作用域 ng-repeat-end ng-repeat-start      更新时间:2023-09-26

我试图将字符串放在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