Maison > Questions et réponses > le corps du texte
<!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中文网2017-05-15 17:04:35
Écrivez ceci :
<ul>
<li ng-repeat="x in names" id="{{ 'name' + $index }}" >
{{ x.name + ', ' + x.country }}</li>
</ul>