search

Home  >  Q&A  >  body text

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 days ago581

reply all(1)I'll reply

  • PHP中文网

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

    Write this:

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

    reply
    0
  • Cancelreply