AngularJS:提醒不显示时,多个消息更改ngModel消息 [英] AngularJS: Alerts don't show up when multiple messages change ngModel for message
问题描述
-
我有一个通知服务,可让效果很好,当页面加载和控制器被加载
I have a notification service which works well for when page is loaded and Controller is loaded
但是,当我有不同的按钮调用不同的功能,他们变的消息,但警报显示不出来
But when I have different buttons calling different functions, they change message, but alerts don't show up
下面是一个plunker - http://plnkr.co/edit/ YioiJXNkaET6T2mexjCq?p = preVIEW
Here is a plunker for that - http://plnkr.co/edit/YioiJXNkaET6T2mexjCq?p=preview
什么是我需要做的更新它,每当 $ scope.message
的变化?
What is that I need to do to update it whenever $scope.message
changes?
推荐答案
您可以 $观看
模型,并显示报警时,它的变化。
http://plnkr.co/edit/fJuP9LWH4MNVV1cQs3ED?p=$p$pview一>
You could $watch
the model and show the alert when it changes.
http://plnkr.co/edit/fJuP9LWH4MNVV1cQs3ED?p=preview
在你的指令链接功能:
link: function(scope, element, attrs) {
scope.$watch('ngModel', function() {
element.show();
$timeout(function(){
//element.empty();
element.hide();
}, 5000);
});
}
这篇关于AngularJS:提醒不显示时,多个消息更改ngModel消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!