Javascript AngularJS指令单击只能调用一次
我正在制定一个指示来展示一种模式。它在第一次到第二次或之后的任何时间工作,单击不再工作。代码如下所示:Javascript AngularJS指令单击只能调用一次,javascript,angularjs,Javascript,Angularjs,我正在制定一个指示来展示一种模式。它在第一次到第二次或之后的任何时间工作,单击不再工作。代码如下所示: <li><a href="http://example.com/JohnDoe" profile-modal="JohnDoe">JohnDoe</li> EngagementApp.directive('profileModal', ['$compile', 'Request', '$modal', '$q', }])) 我怎样才能让点击多次而不是第一
<li><a href="http://example.com/JohnDoe" profile-modal="JohnDoe">JohnDoe</li>
EngagementApp.directive('profileModal', ['$compile', 'Request', '$modal', '$q',
}]))
我怎样才能让点击多次而不是第一次工作?我用于模态的框架是angularstrap 第一次单击带有该指令的链接时,它在element.bind中执行代码。但是如果我再次单击它,将不再调用element.bind中的代码。我通过在element.bind函数中输入console.log('Test')消息来测试它。更正,代码正在执行,只是模式代码没有执行。我添加到控制台日志以进行测试。因为没有人知道您在模型对话框中使用的框架,所以没有人能够帮助您。我使用的是angular strap。我相信您需要使用$modal()调用返回的承诺(不要忘记注入
$q
服务)。类似于:$q.when($modal({…})).then(function(modalHandle){modalHandle.modal('show');});
return {
restrict : 'A',
link : function(scope, element, attrs) {
element.bind('click', function(e) {
e.preventDefault();
scope.modal = {
username : attrs.profileModal,
url : main_site_url
};
var modalPromise = $modal({template: '/templates/profile.html', persist: true, show: false, backdrop: 'static', scope: scope});
$q.when(modalPromise).then(function(modalEl) {
modalEl.modal('show');
});
});
}
};