Angular UI Bootstrap 警报未关闭

Posted

技术标签:

【中文标题】Angular UI Bootstrap 警报未关闭【英文标题】:Angular UI Bootstrap alert is not closing 【发布时间】:2014-04-10 00:48:06 【问题描述】:

我已经复制了 Angular Uis 示例,但它没有关闭。 尽管我的关闭函数正在被调用等,并且还尝试手动将警报设置为 null 并且没有运气。

html

<alert ng-repeat="alert in cantVoteWhenNotLoggedInAlerts" 
    type="alert.type"
    close="closeCantVoteWhenNotLoggedInAlert($index)"> alert.msg 
</alert>

javascript

//add
$scope.cantVoteWhenNotLoggedInAlerts.push(
  type: 'warning',
  msg: 'Must be logged in'
);                                

$scope.closeCantVoteWhenNotLoggedInAlert = function (index) 
  $scope.cantVoteWhenNotLoggedInAlerts.splice(index, 1);
;

【问题讨论】:

好像没问题,能发个jsfiddle吗? 您的代码有效。这是Js Fiddle。 jsfiddle.net/alaksandarjesus/j9ks1uc6 【参考方案1】:

试试这个方法,效果不错

<alert ng-repeat="alert in cantVoteWhenNotLoggedInAlerts" type="alert.type"
      ng-click="closeCantVoteWhenNotLoggedInAlert(this)"> alert.msg </alert>


$scope.closeCantVoteWhenNotLoggedInAlert = function (this) 
            $scope.cantVoteWhenNotLoggedInAlerts.splice(this.$index, 1);
        ;

【讨论】:

不适合我,不应该将“this”作为参数传入吗?也许是因为我的警报已经在重复了

以上是关于Angular UI Bootstrap 警报未关闭的主要内容,如果未能解决你的问题,请参考以下文章