我有个按钮:
<button ng-click="deleteCompany(company.id)"
class="btn btn-danger"
onClick="return window.confirm('This will permernently delete the entity\n
Are you sure you want to delete this post?'); ">
<span class="glyphicon glyphicon-trash"></span>
</button>我也有一个角函数:
$scope.deleteCompany = function(id){
console.log(id);
}当我在确认控制台输出中单击cancel时:
1在“确认控制台输出”中单击“确定”时:
1我希望角码在按下"Ok“时执行,而不是在按下"Cancel”时执行。
JSFiddle示例:http://jsfiddle.net/4304ewu5/
发布于 2016-05-04 12:41:50
将confirm抛到$scope.deleteCompany()函数中:
function MyCtrl($scope) {
$scope.deleteCompany = function(id) {
if (confirm('This will permernently delete the entity\nAre you sure you want to delete this post?')) {
$scope.name = id;
// delete the stuff.
}
}
}并将其从内联HTML中删除:
<div ng-controller="MyCtrl">
<button ng-click="deleteCompany('1')" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
<button ng-click="deleteCompany('2')" class="btn btn-danger">
<span class="glyphicon glyphicon-trash"></span>
</button>
Hello, {{name}}!
</div>Fiddle: http://jsfiddle.net/0Laztrfk/
发布于 2016-05-04 12:41:38
为什么不将confirm放在deleteCompany方法中呢?
$scope.deleteCompany = function(id) {
if (!confirm("Delete company?"))
return;
console.log(id);
}https://stackoverflow.com/questions/37028105
复制相似问题