【问题标题】:Ng-repeat alert [duplicate]Ng-重复警报[重复]
【发布时间】:2020-03-05 11:34:22
【问题描述】:

我有以下

<tr ng-repeat="sce in users">
  <td>
    <a href="/test/delete?id={{sce.id}}" 
        onclick="return confirm('You really want to delete'+ {{sce.name}} + 'from list');" >
           <span aria-hidden="true" class="glyphicon glyphicon-remove-circle"></span>
    </a>
  </td> 
</tr>

但是当我点击,去删除时,我没有看到警报

我在控制台中收到错误:

Error: [$compile:nodomevents] http://errors.angularjs.org/1.5.3/$compile/nodomevents

【问题讨论】:

标签: javascript angularjs


【解决方案1】:

试试这个解决方案:

<a href="/test/delete?id={{sce.id}}" 
    ng-click="showAlert($event, sce.name)" >

将这样的方法添加到控制器中:

$scope.showAlert = (event, name) => { 
   event.preventDefault(); 
   let result = confirm('You really want to delete'+ name + 'from list');
   if(result) {
     // Do a rest api to delete the item
   }
}

【讨论】:

  • 我更改了 ng-click="showAlert($event, sce.name)"。现在我说警报但是当我点击确定时不会重定向
  • 我编辑我的答案。我的建议是使用 $http.post
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-08-11
  • 2016-05-28
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多