搜尋

首頁  >  問答  >  主體

angular.js - ngReapeat迴圈的標籤如何命名ID

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="http://apps.bdimg.com/libs/angular.js/1.4.6/angular.min.js"></script> 
</head>
<body>

<p ng-app="" ng-init="names=[
{name:'Jani',country:'Norway'},
{name:'Hege',country:'Sweden'},
{name:'Kai',country:'Denmark'}]">

<p>循环对象:</p>
<ul>
  <li ng-repeat="x in names" id="'name'+$index" >
  {{ x.name + ', ' + x.country }}</li>
</ul>

</p>

</body>
</html>

想要id是name0、name1、name2,結果原封不動

PHP中文网PHP中文网2745 天前582

全部回覆(1)我來回復

  • PHP中文网

    PHP中文网2017-05-15 17:04:35

    這麼寫:

    <ul>
      <li ng-repeat="x in names" id="{{ 'name' + $index }}" >
      {{ x.name + ', ' + x.country }}</li>
    </ul>

    回覆
    0
  • 取消回覆