Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AngularJS: Better way to display success messages

Tags:

angularjs

$('body').on('click', '#save-btn', function () { 
      $('#greetingsModal').modal('show'); 
 });


<div id="greetingsModal" class="modal hide fade" tabindex="-1" role="dialog" aria-  labelledby="myModalLabel" aria-hidden="true">
<div class="alert alert-success">        
     <a href="../admin/Supplier" class="close" data-dismiss="alert">x</a>
    <strong>Well done!</strong>.
</div>

I want to display a popup message using the above styles whenever 'save-btn' is clicked. The above code works fine but there is a lot of time delay by doing it this way. Is there any way to display such a alert message using angular?

like image 683
user Avatar asked Oct 18 '13 03:10

user


2 Answers

Bootrstrap-UI has pretty good alert. We can use the same place for all alerts. Just modify content.

HTML

<div class="alert alert-success" ng-show="showSuccessAlert">
   <button type="button" class="close" data-ng-click="switchBool('showSuccessAlert')" >×</button>
   <strong>Done!</strong> {{successTextAlert}}
 </div>

JS

$scope.successTextAlert = "Some content";
$scope.showSuccessAlert = true;
....
// switch flag
$scope.switchBool = function(value) {
   $scope[value] = !$scope[value];
};

Demo Fiddle

[EDIT]

if you interesting to put alert into dialog, here is other Demo in Plunker

like image 169
Maxim Shoustin Avatar answered Sep 28 '22 04:09

Maxim Shoustin


I would be wary of mixing jQuery and Angular, it works but can get messy. You may be interested in the Bootstrap-UI Modal here: http://angular-ui.github.io/bootstrap/#/modal It can do what you want and more.

like image 43
TyndieRock Avatar answered Sep 28 '22 02:09

TyndieRock