Bom dia, na aula utilizamos nativeElement e blindamos om isPlataformBrowers.
Procurei porém acredito que a equipe do manteve depreciado o invokeElementMethod. Minha duvida é se poderia ao invés de criar platorf detector, utilizasse selectRootElement do Render2 estaria blindado no SRR ?
Minha implementação ficou
@Component({
templateUrl: 'signin.component.html'
})
export class SigninComponent implements OnInit {
loginForm!: FormGroup;
@ViewChild('userNameInput') userNameInput!: ElementRef<HTMLInputElement>;
constructor(
private readonly _router: Router,
private readonly _formBuilder: FormBuilder,
private readonly _authService: AuthService,
private readonly _platFormDetectorService: PlatformDetectorService,
private readonly _renderer: Renderer2
) {}
ngOnInit(): void {
this.loginForm = this._formBuilder.group({
userName: [null, Validators.required],
password: [null, Validators.required]
});
}
login() {
const userName = this.loginForm.get('userName')?.value;
const password = this.loginForm.get('password')?.value;
this._authService.authenticate(userName, password)
.subscribe(
() => this._router.navigate(['user', userName]),
err => {
this.loginForm.reset();
this._renderer.selectRootElement(this.userNameInput.nativeElement).focus()
// this._platFormDetectorService.isPlatformBrowser() && this.userNameInput.nativeElement.focus();
alert(`${err.status} - ${err.statusText}`)
}
)
}
}