Search code examples
angularangular-ng-if

Getting state of element in angular 4


Basic question on angular binding

<input type="checkbox" aria-selected="false" name="test">

<input name="user" *ngIf="?">

can i bind/listen to element "test", when check box is selected input element "user" should be enabled. what should go into ngIf condition. can this be done without using ngmodel binding


Solution

  • Try using reference:

    <input type="checkbox" aria-selected="false" name="test" #checkbox>
    <input name="user" *ngIf="checkbox.checked">
    

    Although, chances are that checkbox.checked will not be updated, after you change checkbox state. Then try something like this:

    <input type="checkbox" aria-selected="false" name="test" #checkbox ngModel>
    <input name="user" *ngIf="checkbox.checked">