daydreamer
daydreamer

Reputation: 91959

AngularJS: Alerts don't show up when multiple messages change ngModel for message

Here is a plunker for that - http://plnkr.co/edit/YioiJXNkaET6T2mexjCq?p=preview

What is that I need to do to update it whenever $scope.message changes?

Upvotes: 2

Views: 1525

Answers (1)

Tosh
Tosh

Reputation: 36030

You could $watch the model and show the alert when it changes. http://plnkr.co/edit/fJuP9LWH4MNVV1cQs3ED?p=preview

In linker function of your directive:

link: function(scope, element, attrs) {
  scope.$watch('ngModel', function() {
    element.show();
    $timeout(function(){
      //element.empty();
      element.hide();
    }, 5000);
  });
}

Upvotes: 4

Related Questions