A
A
Alexander Wolf2014-02-02 21:50:48
JavaScript
Alexander Wolf, 2014-02-02 21:50:48

How to organize popup windows in angular?

Hello! I have popup windows on my site. When you click certain buttons (such as "Add Code", "Add Store") they should pop up. What is the best way to organize it? Use just DOM (and CSS) or inject scope variables?
Now it works like this:

app.directive('showPopup', function () {
  return {
    restrict: 'A',
    link: function (scope, elem, attrs) {
      $(elem).click(function () {
        $('#' + attrs['showPopup']).fadeIn(function () {
          // некая логика
        });
      });
    }
  }
});

I think it would be more correct to use a scope variable, along with ng-if. However, popups and buttons are at the disposal of different controllers (which, in general, is not a problem, because there is a $rootScope. Right?).

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
styv, 2014-02-03
@styv

It is best to implement modal windows through a service.
Have a look at the ready-made solutions:
Under bootstrap angular-ui.github.io/bootstrap/#/modal
For simpler cases, I used this https://github.com/btford/angular-modal with some improvements.
In the most simplified version, it can be implemented through a directive that will simply hang an event on an element and call your popup plugin (if you have one).

V
Valery, 2014-08-25
@Akuma

Although a lot of time has passed, I think this article of mine on the implementation of simple modal windows in Angular will not be superfluous: akuma.su/blog/vsplyvayuschie-okna-na-angularjs.html

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question