来自ng-repeat的离子条件ng-src

时间:2016-05-13 10:32:29

标签: angularjs ionic-framework

我希望根据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>

1 个答案:

答案 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>