我有以下問題:我想專注於一個輸入。但我有一個微調控件在頁面加載時被觸發,並且只有在某些http請求完成時纔會隱藏。此外,所有的輸入都被禁用,直到請求沒有完成。所以它看起來像這樣:焦點HTML元素啓用後
<fieldset ng-disabled="!noPendingRequests">
...
<input id="input-to-focus-on" uib-datepicker-popup="MM/dd/yyyy" type="text" ng-model="startDate" ... />
<spinner ng-hide="noPendingRequests"></spinner>
</fieldset>
Spinner是一個自定義的Angular指令。有要求自動對焦#input-to-focus-on
輸入,但它不起作用。在所有的http請求都使用$q.all
解析後,我試圖集中注意力。但這並不起作用。我想這是因爲在啓用輸入之前觸發$q
中的回調。我也試過這樣的手動啓用:
$q.all(somePromises).then(function() {
angular.element('#input-to-focus-on')[0].disabled = false;
angular.element('#input-to-focus-on')[0].tabIndex = 1;
angular.element('#input-to-focus-on').focus();
});
我不知道該怎麼做,並希望有任何幫助。在此先感謝,夥計們!
值得一試[ngFocus指令(https://docs.angularjs.org/api/ng/directive/ngFocus),因爲它是建立在角流。 – GillesC
@GillesC感謝您的建議,但遺憾的是它不工作太 –
@GillesC這個怎麼樣一個https://gist.github.com/zbicin/2b3fdf538936287c1a96?爲了達到這個目的,我前一段時間已經做了。 –