2017-02-27 20 views
0

如何將焦點設置到我的kendoui multiselect元素上,在view init(ngAfterViewInit)之後?將注意力集中在kendoui multiselect

在正常輸入元素我將焦點設置,如:

HTML:

<input #setFocus type="text" class="form-control" formControlName="code" id="code" /> 

組件:

@ViewChild('setFocus') focusElement: any; 
... 
ngAfterViewInit() { 
    if (this.focusElement) { 
     this.focusElement.nativeElement.focus(); 
    } 
} 

感謝您的幫助!在他們的documentation

+0

焦點|模糊支持的改進計劃 - https://github.com/telerik/kendo-angular/issues/335 。直到它被實現,您將需要使用一些在此給出的建議線。 –

+1

感謝您的回答!我將等待焦點/模糊支持。 –

回答

0

來看,你可以使用open輸入

@Component({ 
    selector: 'tester', 
    template: ` 
     <kendo-multiselect #setFocus [data]="items"></kendo-multiselect> 
    ` 
}) 
class TesterComponent { 

    @ViewChild('setFocus') 
    focusElement: MultiSelectComponent; 

    ngAfterViewInit() { 
     this.focusElement.open = true; 
    } 
} 

您可以切換本作例如,通過使用[open]爲模板輸入。

0

感謝您的回答。

當我設置輸入[open]="true"時,將打開多選控件的彈出窗口。

但我需要在加載視圖後將光標設置到多選控件的文本輸入字段中。因此,用戶可以開始輸入和過濾數據,而不需要先點擊控件。

0

你總是可以看看HTML如何呈現控件,你可以使用。

let el = this.focusElement.nativeElement; 

if (el.className.indexOf("k-multiselect") != -1) { // kendo multiselect 
    el.children[0].children[1].children[0].focus(); 
} 

或使用jQuery

let el = this.focusElement.nativeElement; 
$(el).find(".k-input").focus(); 

直到劍道正確實現此。

相關問題