<button alloy #initialFocus></button>
при доступе через:
ngOnInit(): void {
this.initalFocusButton.focus(); // undefined unless it's an ElementRef
}
отображается неопределенным в OnInit и AfterViewInit (ng8, поэтому это не имеет значения). Я пробовал различные комбинации read
и селектора, но он может быть запрошен только как ElementRef
. Существуют ли ограничения для запроса директивы для собственного элемента?
AlloyButtonDirective
:
@Directive({
selector: `button [alloy]`
})
export class AlloyButtonDirective implements AfterViewInit, OnDestroy {
private unsubscribe = new Subject();
// Default mode: Standard
private currentStyle = Styles.Standard;
@HostBinding(`class.alloy-button-standard`) @Input('standard')
get isStandard() { return this.currentStyle === Styles.Standard; }
set isStandard(value: any) {
if (value !== false) {
this.currentStyle = Styles.Standard;
}
}
// More styles and a focus monitor.
...