@ViewChild
can access only local
template of component, not parent or child components.
@Component({ selector: 'app-login', template: ` <re-captcha></re-captcha> <div #refname></div> `, styleUrls: ['./login.component.css'] }) export class LoginComponent implements OnInit, AfterViewInit { @ViewChild(RecaptchaComponent) reCaptcha: RecaptchaComponent; @ViewChild('refname') input: ElementRef; constructor() { console.log(this.reCaptcha); // null } ngAfterViewInit(): void { console.log(this.reCaptcha); // not null } } |