AngularJS - directive ng-repeat 14388247
by mrajcok
HTML
<div ng-app="myApp">
<div ng-controller="ctrl">
<mylist></mylist>
<a ng-click="changeItems()">change item 0</a>
</div>
</div>
JavaScript
var myApp = angular.module('myApp', [])
.controller('ctrl', function ($scope) {
$scope.items = ['one', 'two', 'three'];
$scope.changeItems = function() {
$scope.items[0] = 1;
}
})
.directive('mylist', function () {
return {
restrict:'E',
replace: true,
scope: true,
template: [
'<ul>',
'<li ng-repeat="myItem in items">{{myItem}}</li>',
'</ul>'
].join('')
}
});