尝试通过 ng-click 删除列表,但 html 和 Controller 似乎无法通信。
<div class="list-group">
<span ng-repeat="list in vm.lists"
class="list-group-item">
<a class="btn btn-primary pull-right" ng-click="vm.elim(list)">
<i class="glyphicon glyphicon-trash"></i>
</a>
<a class="btn btn-primary pull-right" ui-sref=
"lists.view({ listId:list._id })">
<i class="glyphicon glyphicon-edit"></i>
</a>
<h4 class="list-group-item-heading" ng-bind="list.name"></h4>
</span>
</div>
function elim(list) {
alert("works");
if ($window.confirm('Are you sure you want to delete?')) {
vm.list.$remove($state.go('lists.list'));
}
}
单击图标时至少应该有一个警报,但什么也没有发生。有建议吗?
最佳答案
就像 Esteban 所说,你的 elem 函数应该是作用域变量的一部分,例如
$scope.vm.elem = function(){};
关于javascript - HTML 按钮和 Controller 未连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39454573/