Home > Software engineering >  Angular Toggle Button not working as expected
Angular Toggle Button not working as expected

Time:01-18

Trying to implement toggle functionality in angular so when button is toggled different text is displayed. Error is thrown in my code. Any help? Code below.

HTML

Otto {{isChecked ? 'ACCESS' : 'NO ACCESS'}}
TS
isChecked: boolean;

CodePudding user response:

try something like below

HTML

<tr>
<td>Otto</td>
<td><button >{{isChecked ? 'ACCESS' : 'NO ACCESS'}}</button></td>
<td>
   <div >
      <input  type="checkbox" (change)="getValue()">
   </div>
</td>
</tr> 

TS

  isChecked: boolean = true;

  getValue() {
    this.isChecked = !this.isChecked;
  }
  •  Tags:  
  • Related