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>
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>
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;
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With