【发布时间】:2015-06-29 08:22:49
【问题描述】:
我正在尝试为模态框编写一个简单的指令,以便在我在其中提交表单时关闭它们。
我有 2 个模式:登录模式和注册模式,分别在我的 html 中排序。
模态框位于 modals.html 中,该文件在 html 文件中使用 ng-include 调用,该文件也在 ng-include 中调用,因此我们这里有一个 childscope 的 childscope
我的指令
.
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();
});
}
};
});
不知道为什么link里面的元素会被最后一个元素覆盖?
我正在对我的两个模态应用 my-modal 指令,但我打开了第一个。
任何帮助将不胜感激
【问题讨论】:
标签: javascript jquery html angularjs twitter-bootstrap