How to reuse cross component methods?

27 views
Skip to first unread message

Sean Bornstein

unread,
Oct 31, 2020, 2:20:08 AM10/31/20
to Angular and AngularJS discussion
Hello all,

I have in multiple components public methods that set public properties within the component.   Those properties are the in the HTML template being used for things.   I have the same public method and HTML template reference across multiple components.   How can I consolidate these in a single ts file or best way to handle that.  None of these methods are calling an API etc. into a service call its more business logic and setting these properties.

Thanks for any info.

Arnaud Deman

unread,
Oct 31, 2020, 5:39:35 AM10/31/20
to Angular and AngularJS discussion
Maybe you could use some kind of delegate that wraps the business logic, all of your components would have an instance of that delegate, and the properties would be accessible in template like this: theDelegate.theProperty.
If you want to reuse some template elements as well, you can also have an child component accessible in the parent with @ViewChild.

My two cents!
Regards,
Arnaud.
Reply all
Reply to author
Forward
0 new messages