<!DOCTYPE html>
<html ng-app="myapp">
<head lang="en">
<meta charset="UTF-8">
<title></title>
<script src="angular.min.js"></script>
<script>
var m1 = angular.module('myapp',[]);
m1.controller('Aaa',function($scope){
$scope.colors = [{
'id':'1',
'name':'red'
},{
'id':'2',
'name':'green'
},{
'id':'3',
'name':'blue'
}];
});
</script>
</head>
<body>
<p ng-controller="Aaa">
<ul>
<li ng-repeat="color in colors">{{color.name}}</li>
</ul>
</p>
</body>
</html>
Do I need to use the ID to match it?
It doesn’t have to be as complicated as the one above.
The subject should use Angular’s directive to achieve this requirement.
Result: http://output.jsbin.com/rolobakaya
My thoughts are:
Then define a
ng-click
并在里面修改$scope.currentId