使用确认从按钮中的javascript停止角度

Mag*_*use 0 javascript angularjs

我有一个按钮:

<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>
Run Code Online (Sandbox Code Playgroud)

我也有一个角度函数:

$scope.deleteCompany = function(id){
        console.log(id);
}
Run Code Online (Sandbox Code Playgroud)

当我在确认控制台输出时单击取消时:

1
Run Code Online (Sandbox Code Playgroud)

当我在确认控制台输出时单击确定:

1
Run Code Online (Sandbox Code Playgroud)

我希望在按下"确定"时执行角度代码,而不是在按下"取消"时执行.

JSFiddle示例:http://jsfiddle.net/4304ewu5/

Pra*_*man 5

抛出你的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.
    }
  }
}
Run Code Online (Sandbox Code Playgroud)

并从内联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>
Run Code Online (Sandbox Code Playgroud)

小提琴:http://jsfiddle.net/0Laztrfk/