Skip to content

Instantly share code, notes, and snippets.

@hunterlord
Created October 2, 2017 06:20
Show Gist options
  • Save hunterlord/f61237509837dd07a66189c7ed21c334 to your computer and use it in GitHub Desktop.
Save hunterlord/f61237509837dd07a66189c7ed21c334 to your computer and use it in GitHub Desktop.
angular viewchild under *ngIf , always get undefined
```typescript
<pre>{{test.value}}</pre>
<button (click)="isVisible = true">Show it</button>
<input #test *ngIf="isVisible">
Then in your component you "grab" the test element like this:
private test: ViewContainerRef;
@ViewChild('test') set someDummySetterName(theElementRef: ViewContainerRef) {
this.test = theElementRef;
}
````
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment