I study Angular and make a universal directive to call PopUp windows.
What I want: In Dom should be called through the tag
<pop-up-dialog url="loginFrame"></pop-up-dialog> where url="loginFrame" is the identifier of the template being loaded.
Something I got confused already and I do not see how to implement it, so that the opening and closing of PopUp windows is done with the help of a single directive.
script.js
var mainModule = angular.module("mainModule", []) var listUrl = [ { name: 'loginFrame', url: '../views/header/loginFrame.html', tag: 'showLoginPopUpDialog', tagvalue: false }, { name: 'regFrame', url: '../views/header/regFrame.html', tag: 'showRegPopUpDialog', tagvalue: false } ]; mainModule.controller('mainController', function($scope) { $scope.onLoginFrame = function(fname) { for (var i=0; i < listUrl.length; i++) { if( fname == listUrl[i].name) { listUrl[i].tagvalue = true; } } } }); mainModule.directive('popUpDialog', function() { return { //директива подставляет нужные шаблоны, эта часть работает restrict: 'E', scope: false, templateUrl: function(elem, attrs) { for (var i=0; i < listUrl.length; i++) { if( attrs.url == listUrl[i].name) { return listUrl[i].url; } } return ''; }, link: function(scope, elem, attrs) { // Здесь я хочу добавить в шаблон атрибут ng-show значение которого он будет получать через массив listUrl var attrname = 'showLoginPopUpDialog'; var pudialog = angular.element('<pudialog ng-show="'+attrname+'" pudialog></pudialog>'); elem.append(pudialog); }, } }); <!-- file loginFrame.html --> <div class="login-frame-bg" pudialog> <h2>Окно авторизации</h2> <p>Close</p> </div>