0
我正在使用角度實現ui-select
。它工作正常,但element[0].focus()
不適用於它。爲了進一步解釋,我有以下指令對ui-select
上ui-select
元素[0] .focus不能與角度ui選擇
var focusIf = function ($timeout, $parse) {
return {
require: "ngModel",
//scope: {
// updateFrom: "&"
//},
link: function (scope, element, attrs, ngModel) {
console.log("in focus if");
var focusChecker = $parse(attrs.focusIf);
scope.$watch(function() {
return focusChecker(scope);
}, function (newVal, oldVal) {
console.log("new val", newVal);
console.log("old val", oldVal);
if (newVal === true && !oldVal) {
console.log('inside condition');
console.log("element", element[0]);
$timeout(function() {
element[0].focus();
});
}
})
}
};
};
app.directive("focusIf", focusIf);
焦點設置我使用這個指令像
<ui-select name="supplierId" data-focus-if="isSupplierInvoice()" ng-model="transaction.SupplierInvoice.supplierId" theme="select2" data-ng-show="isSupplierInvoice()" data-ng-required="isSupplierInvoice()" data-ng-disabled="disabled" style="width:100%;">
<ui-select-match placeholder="Select a supplier or search...">{{$select.selected.Name}}</ui-select-match>
<ui-select-choices repeat="supplier.ID as supplier in suppliers | propsFilter: {Name: $select.search, IdentityNumber: $select.search}">
<div ng-bind-html="supplier.Name | highlight: $select.search"></div>
<small>
Identity Number: <span ng-bind-html="''+supplier.IdentityNumber | highlight: $select.search"></span>
</small>
</ui-select-choices>
</ui-select>
的isSupplierInvoice()
變成定期的HTML的變化事件真正降下來了。但即使函數返回true,焦點也不會到達ui-select
。我已驗證該指令,它對正常的html輸入正常工作。
有一件事值得一提的是,我成功打入了指令的if條件。這意味着在'timeout()'方法中調用'element [0] .focus()',但它不適用於'ui-select'。 –
你有沒有發現這個問題?我有同樣的問題。 – user3377450