使用img ng-src显示图像不工作的数组

问题描述 投票:0回答:1

我在显示图像数组时阅读了一些使用ng-src的解决方案,但它似乎无法正常工作。数组中只有1项接受显示。对此有何解决方案?我也尝试了img [src],但它没有工作。

这是我试过的

angular.module('selectExample', [])
  .controller('ExampleController', ['$scope', function($scope) {
 
    $scope.register = {
      regData: {
        branch: {},
      },
      names: [{
        name:"narquois",
        image:[
        "https://picsum.photos/200",
        "https://picsum.photos/200/300/?random"]
        
        },
        {
        name:"velvet",
        image:[
        "https://picsum.photos/200"]
        
        }],
    };

  }]);
img{
width:70px;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.7.5/angular.min.js"></script>
<div ng-app="selectExample" ng-controller="ExampleController">
<table id="example" width="100%">
    <thead>
       <tr align="center">
         <th>Name</th>
         <th>Image</th>
       </tr>
    </thead>			
    <tbody>
       <tr ng-repeat="person in register.names">
         <td align="center">{{ person.name }}</td>
         <td align="center"><img ng-src="{{ person.image }}"></td>
       </tr>
    </tbody>
</table> 
</div>
javascript angularjs mean-stack
1个回答
2
投票

您目前没有循环遍历不同的图像。

尝试用此替换ng-repeat,看看这是否是您想要的效果。

       <tr ng-repeat="person in register.names track by $index">
         <td align="center">{{ person.name }}</td>
         <td align="center">
           <img ng-repeat="image in person.image" ng-src="{{image}}" />
         </td>
       </tr>
© www.soinside.com 2019 - 2024. All rights reserved.