Reputation: 2190
I have used google place api following this
but i am getting this error below
ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'nativeElement' of undefined
-html file
<div class="form-group" [formGroup]="myGroup">
<input placeholder="search for location" autocorrect="off" autocapitalize="off" spellcheck="off" type="text" class="form-control" #search formControlName="searchControl">
</div>
-typescript file:
@ViewChild("search") searchElementRef: ElementRef;
ngAfterViewInit() {console.log(this.searchElementRef)}
I want to use this.searchElementRef.nativeElement.
Upvotes: 0
Views: 1124
Reputation: 6548
avoid using *ngIf and handle this case by display: none or hidden, this is probably due to if the child is defined as a nested child of a ngIf element ngAfterViewInit() is run blindly.checking if child load in dom or not. have a look at this GitHub issue.
Upvotes: 1