cantVoteWhenNotLoggedInAlerts

cantVoteWhenNotLoggedInAlerts

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

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

最佳答案

尝试这种方式,它正在工作

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

10-07 14:24