Created
October 2, 2017 06:20
-
-
Save hunterlord/f61237509837dd07a66189c7ed21c334 to your computer and use it in GitHub Desktop.
angular viewchild under *ngIf , always get undefined
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
```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