我希望根据ng-repeat列表中的人的条件显示适当的avator-image。以下代码未显示avator图像:
$scope.getAvator = function (person) {
if (person.group_id == 1) {
return '1.png'
}
else if (person.group_id == 2) {
return '2.png'
}
else if (person.group_id == 3) {
return '3.png'
};
};
在视图中:
<a class="item item-avatar" ng-repeat="person in people">
<img ng-src="img/class-avators/{{getAvator}}">
<h3>{{person.name}}</h3>
<p>{{person.class }}</p>
</a>
答案 0 :(得分:1)
尝试使用getAvator()
<a class="item item-avatar" ng-repeat="person in people">
<img ng-src="img/class-avators/{{getAvator(person)}}">
<h3>{{person.name}}</h3>
<p>{{person.class }}</p>
</a>