1

component.html

<div class="col-lg-6">
    <div class="form-check position-absolute">
        <input type="checkbox" class="form-check-input" id="exampleCheck1" [checked] = true >
    </div>
    <app-stackbar-chart [data]="exp_month_data"></app-stackbar-chart>
    <app-stackbar-chart [data]="exp_data_performance"></app-stackbar-chart>
</div>

question description

I want to toggle these two divs(app-stackbar-chart) on check and uncheck of that checkbox

3
  • You can use *ngIf for that. Something like *ngIf="!checked". Commented Mar 22, 2019 at 10:18
  • i tried but its not working.. can you please post how should i implement Commented Mar 22, 2019 at 10:21
  • Please refer this link may be it's help you stackoverflow.com/questions/50946102/toggle-div-with-angular-6 Commented Mar 22, 2019 at 10:51

1 Answer 1

1

component.ts

//declare variable for chacked/unchecked

isChecked:boolean = true;

component.ts

<div class="col-lg-6">
    <div class="form-check position-absolute">
        <input type="checkbox" (change)="isChecked =! isChecked" class="form-check-input" id="exampleCheck1" [checked] = true >
    </div>
    <app-stackbar-chart *ngIf="isChecked" [data]="exp_month_data"></app-stackbar-chart>
    <app-stackbar-chart *ngIf="!isChecked" [data]="exp_data_performance"></app-stackbar-chart>
</div>
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.