当我环绕我的input
与ng-if
,隐藏后显示autofocus
属性不生效输入自动对焦:AngularJS - 与NG-如果不工作
下面是代码:
<!DOCTYPE html>
<html ng-app>
<head>
<script data-require="[email protected]" data-semver="1.5.0" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.0/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-init="view={}; view.show = true">
<button ng-click="view.show = !view.show">{{view.show ? "hide" : "show"}}</button>
<div ng-if="view.show">
<input autofocus />
</div>
</body>
</html>
而且这里是plunker: http://plnkr.co/edit/k7tb3xw5AsBYrhdlr3bA?p=preview
只需点击隐藏,然后在显示,你会看到自动对焦不工作!
在铬上的首秀唯一的工作,在FF和IE它不工作了!
我想添加一个东西到你的解决方案 - 前缀的指令。像在'directive(...)'中注册'abcAutofocus'一样在HTML模板中使用'abc-autofocus'以避免混淆使用哪种解决方案 - 纯HTML或Angular指令。 –
Greaaaaaat解决方案。谢谢 –