I'm trying to write a simple directive for modals in order to get them closed when I submit the form inside them.
I have 2 modals : Loginmodal and signup modal, respectively ordered in my html.
The modals are inside a modals.html which is called with a ng-include inside a html file which is also called in ng-include, so we have here a childscope of a childscope
My directive
.
directive('myModal', function() {
return {
restrict: 'A',
scope : { },
link: function(scope, element, attr) {
scope.$parent.$parent.$parent.dismiss = function() {
console.log(element.hasClass('in')); //returns false
element.modal('hide');// doesn't work because element is always the second modal
};
$(element).bind('shown.bs.modal', function () {
if (!scope.$$phase && !scope.$root.$$phase)
scope.$parent.$parent.$parent.$apply();
});
}
};
});
I don't know why the element inside link
is override by the last element?
I'm applying my-modal directive to both my modals but I open the first.
Any help would be very appreciated