**UPDATED ** with a solution that comes close to working:
I'm trying to get my 'skip to content' link to jump to the first focusable element after '#content-start'.
login-base.component.ts:
import { Component, OnInit } from '@angular/core';
import { Inject, Injectable } from '@angular/core';
import { DOCUMENT } from '@angular/platform-browser';
@Component({
selector: 'app-login',
templateUrl: './login.component.html',
styleUrls: ['./login.component.scss']
})
export class BaseLoginComponent implements OnInit {
constructor(
@Inject(DOCUMENT) private document: any
) {
}
skip() {
console.log(document);
console.log(document.querySelector);
var content = document.querySelector(`#content-start`); // ?? document is null!!
if (content) {
var control = content.querySelector('input, button, a');
console.log(control);
//if (control) {
// control.focus(); // first only
//}
}
};
ngOnInit() {
this.document.getElementById('skipLink').onclick = this.skip;
this.document.getElementById('skipLink').onkeypress = function (e) {
if (e.keyCode == 13) {
this.skip();
}
}
}
}
login.component.html:
<div class="login-page">
<section class="main container" id="content-start">
<input type="text"/>
This actually works, inasmuch as console.log(control) returns
<input _ngcontent-c4="" id="username" name="username">
which is actually the correct control.
But I can't just set .focus() because what I have there is an HTML snippet, not an object with methods, such as .focus();
Uh, is there an angular equivalent of jQuery's $(control)?