I wrote a directive that didn't work in firefox (version 36.00) .
我写了一个在firefox中不能用的指令(36.00版本)。
this should be the same with atuofocus attribute in html 5.
这应该与html 5中的atuofocus属性相同。
Here is the code :
这里是代码:
app.directive('autoFocus', function($timeout) {
return {
restrict: 'AC',
link: function(_scope, _element) {
$timeout(function(){
_element[0].focus();
}, 0);
}
};
});
演示
Any idea ? Thanks
任何想法?谢谢
1 个解决方案
#1
2
I had the same problem as you, for firefox you need a workaround, wrap it in a watch:
我和你有同样的问题,对于火狐你需要一个解决方案,用手表包起来:
_scope.$watch('autoFocus', function (value) {
if (value) {
_element[0].focus();
}
});
This should definitely fix your problem.
这肯定能解决你的问题。
#1
2
I had the same problem as you, for firefox you need a workaround, wrap it in a watch:
我和你有同样的问题,对于火狐你需要一个解决方案,用手表包起来:
_scope.$watch('autoFocus', function (value) {
if (value) {
_element[0].focus();
}
});
This should definitely fix your problem.
这肯定能解决你的问题。