Я использую ионный с угловым в компоненте, и я пытаюсь установить фокус программно после загрузки страницы.Это код
item.component.html:
<ion-row>
<ion-col col-5>
<ion-item >
<ion-label>Departure Port</ion-label>
<ion-select #selected class="selector" formControlName="control"
[(ngModel)]="modelItem"
(click)="selectItem()">
<ion-option
*ngFor="let item of [{code:item.code, desc:item.desc}]"
value="{{item.code}}">
{{item.desc}} ({{item.code}})
</ion-option>
</span>
</ion-select>
</ion-item>
</ion-col>
</ion-row>
item.component.ts
export class Item Component implements OnInit, AfterViewInit, AfterViewChecked {
@ViewChild('selector')
private selectorElRef: Select;
public ngAfterViewInit(): void {
this.portSelectorElRef.setFocus();
}
Я также пробовал это:
@ViewChild('selector')
private selectorElRef: Select;
public ngAfterViewInit(): void {
this.portSelectorElRef.getElementRef().nativeElement.focus();
}
И это:
@ViewChild('selector')
private selectorElRef: Select;
public ngAfterViewInit(): void {
this.portSelectorElRef.getNativeElement.focus();
}
variables.scss
*:focus {
border: solid $primary-color 2px;
box-shadow: 5px 10px 8px $primary-color;
}
Ничто из вышеперечисленного не устанавливает фокус на данный элемент.Я попытался установить фокус в AfterViewInit и в AfterViewChecked - тот же эффект (нет).
Вкладка для установки фокуса работает нормально, и стиль применяется, но я не могу в состоянииполучить фокус программно.