0
這是我的問題:我用ng-repeat動態創建按鈕,並且它們的ng-click不起作用。從我到目前爲止發現的情況來看,我必須編譯這些按鈕以確保角度知道新的指令,但我不知道該怎麼做。我試圖創建一個新的指令來做這件事,但我必須做一些錯誤的事情,因爲它仍然不起作用。AngularJS - 通過ng-repeat添加編譯元素
HTML:
<div ng-controller="content">
<ul>
<li ng-repeat="item in items">
<span>item.text {{$index}}</span>
<button ng-click="deleteItem({{$index}})">Delete item</button>
</li>
</ul>
<button ng-click="addItem()">Add item</button>
</div>
JS:
function content($scope) {
$scope.items = [];
$scope.addItem = function() {
$scope.items.push({text: "test"});
};
$scope.deleteItem = function(index) {
$scope.items.splice(index, 1);
};
}
感謝您的答案。
謝謝你的確是:) – 2013-04-07 14:50:20