Components: mat-slide-toggle

Created on 17 Oct 2017  路  6Comments  路  Source: angular/components

Bug, feature request, or proposal:

proposal: Can we have ngOnChanges in slide toggle to monitor dynamic toggle changes?

What is the expected behavior?

When changing the variable for the checked property, the toggle status should change correspondingly.

What is the current behavior?

It doesn't change

What is the use-case or motivation for changing an existing behavior?

when users toggle the slide-toggle, we would like to popup a modal and ask for comments. If users change their mind and hit cancel, we need to switch the slide toggle back to original status.

Is there anything else we should know?

Most helpful comment

I don't think you can do that. You might wanna double check the source code, but I think checked is not an observer, so set checked value dynamic doesn't work. You need to use

 @ViewChild(MatSlideToggle) _SlideToggle: MatSlideToggle;
 this._SlideToggle.toggle();

All 6 comments

Hi @maxisam , I have the same issue today. Can you please tell me how did you fix the problem as I can see you closed the issue :)?

Thank you,
M茅lissa

It was actually dead simple. (change)="onHoldChanged($event)" Somehow I didn't read the document closely.

You can find it in the document here https://material.angular.io/components/slide-toggle/api

Oh actually my problem is a bit different then. I used the same method as you've just mentioned.

My problem is, in my function onHoldChanged, the checked value (true/false) of the slider does not change. The same if I try directly try to set the checked value, the slider does not "slide".

It works onInit, but not after.

I don't think you can do that. You might wanna double check the source code, but I think checked is not an observer, so set checked value dynamic doesn't work. You need to use

 @ViewChild(MatSlideToggle) _SlideToggle: MatSlideToggle;
 this._SlideToggle.toggle();

Oh thank you for the information! It works perfectly, thanks :)

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

_This action has been performed automatically by a bot._

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Miiekeee picture Miiekeee  路  3Comments

Hiblton picture Hiblton  路  3Comments

crutchcorn picture crutchcorn  路  3Comments

theunreal picture theunreal  路  3Comments

constantinlucian picture constantinlucian  路  3Comments