【问题标题】:Angular UI Bootstrap alert is not closingAngular UI Bootstrap 警报未关闭
【发布时间】: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);
};

【问题讨论】:

标签: javascript angularjs angular-ui-bootstrap


【解决方案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”作为参数传入吗?也许是因为我的警报已经在重复了
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-03-06
  • 1970-01-01
相关资源
最近更新 更多