错误:不允许在转发器中重复。 $ index添加了跟踪但数据未显示

时间:2017-04-06 01:52:59

标签: javascript html angularjs ionic-framework

我的webservice返回此字符串:

[{CardNumber:"1234567",CardType:"OPI",CardBalance:"100",
   CardImage:"img/omnipay_card.png"},
 {CardNumber:"5678967",CardType:"MMTC",CardBalance:"200",
   CardImage:"img/mmtc_card.png"},
 {CardNumber:"1011167",CardType:"SEAFR",CardBalance:"300",
   CardImage:"img/seafarers_card.png"}
]

我在html代码中尝试通过$ index添加跟踪来修复错误:

<ion-slide-page ng-repeat="card in cardNumbers track by $index"
      id="mainMenu-slide24"
      style="background:url(&quot;{{card.CardImage}}&quot;) no-repeat center;background-size:cover;">
 <br><br><br><br><br><br><br><br><br><br>
 <h5>Card Number:{{card.CardNumber}}</h5>
 <p><h5>Balance:{{card.CardBalance}}</h5>
</ion-slide-page>

错误消失了,但数据和图像仍未显示。可能是什么问题呢?

1 个答案:

答案 0 :(得分:0)

代码实际上工作正常,检查你的CSS,尝试删除我认为不必要的br标签,

&#13;
&#13;
var myApp=angular.module('myApp',[])
 myApp.controller('myController',function($scope){
  
  $scope.cardNumbers = [{CardNumber:"1234567",CardType:"OPI",CardBalance:"100",CardImage:"img/omnipay_card.png"},{CardNumber:"5678967",CardType:"MMTC",CardBalance:"200",CardImage:"img/mmtc_card.png"},{CardNumber:"1011167",CardType:"SEAFR",CardBalance:"300",CardImage:"img/seafarers_card.png"}];
});
&#13;
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<div ng-app='myApp' ng-controller='myController as vm'>
 <div ng-repeat="card in cardNumbers track by $index" >
 <h5>Card Number:{{card.CardNumber}}</h5><p><h5>Balance:{{card.CardBalance}}</h5></div>
</div>
&#13;
&#13;
&#13;