I have few popups in my application. One is for displaying "About" and the second one for displaying contact form. What I do currently is I put the whole popup DOM into template and write custom directive like this:
angular.module('app').directive('contactForm', function() {
return {
restrict: 'E',
replace: true,
scope: {},
templateUrl: 'contactForm.html',
controller: function($scope) {
$scope.submitForm = function() {
...
}
},
link: function(scope, el) {
scope.$on('openContactForm', function() {
el.show();
});
}
}
});
and call such directive somewhere in my index.html
<body>
<about-popup></about-popup>
<contact-form></contact-form>
...
...
</body>
Somewhere on the page there is controller like this with function bound to button:
angular.module('app').controller('SideBarController', function($scope, $rootScope) {
$scope.openContactForm = function() {
$rootScope.$broadcast('openContactForm');
}
});
I don't feel that's the best way of handling that, but can't figure out how to do this better. Do you have any ideas, examples?