Search code examples
angularjsangularjs-scopeangularjs-service

AngularJS - AlertFactory open dialog behavior


i'm creating an AlertFactory because ui.bootstrap.dialog doesn't works in my app.

So i type follow code: http://jsfiddle.net/Premier/BHqKB/17/

enter code here

It works very well if you click on the "Open dialog" button: on screen appear a dialog with my messages.

I also register a listener on keydown: listener fires a broadcast event on which is registered a scope related function. This function calls openDialog to show the dialog. In this way angular doesn't interpolates arguments and alert is shown with {{title}} placeholder.

What is wrong in my code?

Thank you.


Solution

  • You need an $apply to invoke a digest cycle.

    ng.element(document).on('keydown', function(e){
      //alert('keydown');
      //openDialog();
      $rootScope.$broadcast('openDialog');
      $rootScope.$apply();
    });