【发布时间】:2015-10-22 10:23:08
【问题描述】:
您好,我有一个专注于输入模式的指令。当它是单一模态时,焦点效果很好。在一个例子中,虽然我有一个模态,然后单击此模态上的按钮会在顶部触发另一个模态。然后焦点不起作用。
有什么想法吗?
这是我的代码:
.directive('auto-focus', function ($timeout) {
return {
restrict: 'A',
link: function(scope, el) {
var whiteList = ['input', 'a', 'textarea', 'div']
, tagToFocus = el[0].tagName.toLowerCase()
, allow = whiteList.indexOf(tagToFocus) > -1;
if (!allow) {
throw new Error(`Autofocus is not allowed on ` + tagToFocus);
}
$timeout(() => el[0].focus(), 50);
}
}
【问题讨论】:
-
事实上我做到了,但没有运气。
标签: angularjs modal-dialog focus