Angular UI Bootstrap警报未关闭

时间:2014-03-07 02:48:37

标签: javascript angularjs angular-ui-bootstrap

我已经复制了角度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);
};

1 个答案:

答案 0 :(得分:0)

试试这种方式,它正在运作

<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);
        };