I am trying to toggle button based on backend response.If the response is
Yes, toggle button should be ON, if the response is No, toggle button
should be off.
Below is my html code
<label class="switch">
<input type="checkbox" [ngClass]="{'active': isActive,
'disabled': isDisabled}">
<span class="slider round"></span>
</label>
Below is my component code, where i calling a get service which returns
response either Yes or No.I am calling the service in ngOnit() because i
want to check whether the response is Yes /No when the page loads.Upon
research i came to know we can achieve this using ngclass, but i am not
sure how to do that.
ngOnInit() {
this.service.getFlagStatus().toPromise().then((flagStatus => {
flagStatus= flagStatus.EODStatus;
console.log(flagStatus);
if(flagStatus == 'Yes'){
//toggle right
}else if (flagStatus == 'No') {
//toggle left
}
}));
}
flagStatus variable has the response(Yes/No).
Let me know if i am doing in the right way.
--
You received this message because you are subscribed to the Google Groups
"Angular and AngularJS discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.