【发布时间】:2015-01-27 21:06:48
【问题描述】:
在我的应用程序中(是的,我知道这有点糟糕)在控制器中有这样的代码:
$scope.changePasswordModal = function() {
angular.element('#password-change').modal('show');
};
这段代码是这样出现的:
if(angular.isDefined($routeParams.chgkey)){
$scope.changePasswordModal();
}
我有这样的看法:
<div class="modal custom" id="new-password-remember" tabindex="-1" role="dialog" aria-labelledby="newPasswordRemember" aria-hidden="true" modal-center modal-auto-focus modal-auto-focus-type="1" modal-auto-focus-action="rememberpwd" data-backdrop="static">
....
我在这个视图上还有一些其他的模态形式:当我点击打开模态时 - 一切正常:显示焦点。但是当我打开页面并通过操作在控制器中打开它时,我看到它有焦点,但为什么不显示这个焦点?
指令:
.directive('modalAutoFocus', ['$timeout', '$window', function ($timeout, $window){
return {
restrict: 'EA',
link: function(scope, element, attrs) {
if (attrs.id == 'new-password-change'){
element.find('.on-focus')[0].focus();
}
$(element).on('shown.bs.modal', function(){
element.find('.on-focus')[0].focus();
});
}
}
}]);
我不明白什么是不好的...为什么不显示焦点?我做错了什么?
谢谢
【问题讨论】:
-
带有指令的元素的 id 是 new-user 而不是 new-password-change 是你想要的吗?您的指令是否也在 ID 为 new-password-change 的元素上?
-
@micha 是的,一切都很好,只是我的错误,我更新了问题...
标签: javascript jquery angularjs twitter-bootstrap