This is a migrated thread and some comments may be shown as answers.

set the disabled flag dynamically

2 Answers 348 Views
SplitButton
This is a migrated thread and some comments may be shown as answers.
Jyothi
Top achievements
Rank 1
Iron
Iron
Veteran
Jyothi asked on 03 Feb 2021, 02:09 PM

Hi,

I need to be able to enable/disable dynamically. This is easy when there is a paren child relationship. I can use ViewChild to get access to the disabled variable of the child and that works.

     Example: MySplitButton component have a method to set the flag to true or false

                      setButtonStatus(flag : boolean){
                                  this.isButtonDisabled = flag }

In parent I can access the child and call the method.

 @ViewChild(MySplitButton) splitComponent : MySplitButton;

                     this.splitComponent.setButtonStatus(true);

 

When the MySplitButton component is not the direct child, how do I set access to the this component from lets say grand parent component?

Regards,

Jyothi

2 Answers, 1 is accepted

Sort by
0
Accepted
Dimiter Madjarov
Telerik team
answered on 05 Feb 2021, 06:56 AM

Hello Jyothi,

A possible solution is for the grandparent to invoke a parent method, which will then again invoke the splitbutton method. However the more reliable approach when the state needs to be changed from multiple levels of the component hierarchy is to create a service, responsible for this operation. It could then be injected anywhere, where the state needs to be updated or accessed. Further details about services could be found on the following link:

https://angular.io/tutorial/toh-pt4

Regards,
Dimiter Madjarov
Progress Telerik

Virtual Classroom, the free self-paced technical training that gets you up to speed with Telerik and Kendo UI products quickly just got a fresh new look + new and improved content including a brand new Blazor course! Check it out at https://learn.telerik.com/.

0
Jyothi
Top achievements
Rank 1
Iron
Iron
Veteran
answered on 05 Feb 2021, 12:21 PM

H Dimiter,

I took the first approach as didn't want to create a service just for this functionality. Thanks for the prompt reply.

 

Regards,

Jyothi

Tags
SplitButton
Asked by
Jyothi
Top achievements
Rank 1
Iron
Iron
Veteran
Answers by
Dimiter Madjarov
Telerik team
Jyothi
Top achievements
Rank 1
Iron
Iron
Veteran
Share this question
or