0
我正在与angularjs指令模板挣扎。该{{变量}}工作在NG-重复里面一个很奇怪的方式,AngularJS指令模板ng重复有趣的替换
<div ng-controller="MyCtrl">
<h2>here i am</h2>
<button type="button" ng-click="addItem()" class="btn btn-primary">Howdy</button>
<div ng-repeat="item in items track by $index" itemlist></div>
</div>
<script type="text/ng-template" id="template.html">
<div>
Howdy {{item.itemNum}} {{item.name}}
</div>
</script>
var myApp = angular.module('myApp', []);
myApp.controller('MyCtrl', function ($scope) {
$scope.count = 0;
$scope.items = [];
var newItem = {
itemNum: 0,
name: "New"
};
$scope.addItem = function() {
newItem.itemNum = $scope.count;
console.log('adding item ' + newItem.itemNum);
$scope.items.push(newItem);
$scope.count += 1;
};
});
myApp.directive('itemlist', function ($compile) {
return {
templateUrl: 'template.html',
};
});
我已经创建出我的问题,这里的jsfiddle:http://jsfiddle.net/dk253/8jm5tjvf/23/。
我缺少什么或者做错了吗?
谢谢!
@DaveKearney欢迎您。 – PSL 2015-02-08 01:38:29