Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular.ui alert doesn't close

I'm use the Angular-ui and i want to create single alert. But Alert won't to close

<div ng-controller="AlertCtrl">

     <alert type="danger" close>i'm alert</alert>

</div>
like image 758
Ksvit Avatar asked Mar 01 '26 10:03

Ksvit


2 Answers

actually you don't even need a controller and a function if you place your message in the html:

<alert type="danger" close="bCloseAlert=1" ng-hide="bCloseAlert">i'm alert</alert>
like image 108
ali Avatar answered Mar 03 '26 00:03

ali


If you only ever want to show one alert, you need to change your approach a little.

Your should pass a function from your AlertCtrl's scope to the "close" attribute, like this:

<alert type="{{alert.type}}" close="closeAlert()" ng-show="alert != null">
    {{alert.msg}}
</alert>

Note that your type, and the text of the alert, now reference an alert object. Also note that I have added the ng-show attribute to only show the alert markup if the alert object is not null.

And then implement that function in your controller, and define an alert object for it to manipulate:

$scope.alert = { type: 'danger', msg: 'im alert' };

$scope.closeAlert = function() {
    $scope.alert = null;
}
like image 40
Josh Darnell Avatar answered Mar 02 '26 23:03

Josh Darnell



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!