AngularJS Bootstrap alert dismiss-on-timeout attribute doesn't work

后端 未结 5 1631
春和景丽
春和景丽 2021-01-04 13:28

I\'m trying to use AngularJS Bootstrap alerts like explained here with the \"dismiss-on-timeout\" attribute. It has no effect in this example, the alert just appears regular

5条回答
  •  清酒与你
    2021-01-04 13:49

    I never could get it to work. Here's a more straightforward approach:

    Markup

    close="closeAlert()" alert alert-{{ alert.level }}" ng-show="alert.show"> {{ alert.message }}

    Controller

    $scope.closeAlert = function() {
        $scope.alert.show = false;
    }
    
    $scope.showAlertForFiveSeconds = function(){
        $scope.alert.message = 'Something went wrong!');
        $scope.alert.level = 'danger';  // red
        $timeout(closeAlert, 5000);  // close the alert in 5 seconds
    }
    

    Essentially all I'm doing is manually setting a deferred call to close the alert and walking away.

    Note that doing this also requires you to inject the Angular $timeout service into the controller up top.

提交回复
热议问题