Sharing UI functionality among controllers, the right way?

30 views
Skip to first unread message

Boyan Djumakov

unread,
Oct 29, 2015, 8:33:11 AM10/29/15
to AngularJS
Hello everybody,
I've recently dealt with a big angular app. In it we have a controller A that is in a static place, let's say header functionality. We have controllers B and C that load dynamically in an ng-view, based on route.
In Ctrl B I have a UI functionality that opens a window with some data and functionality inside. This UI functionality is needed though in the other Ctrl C and at some point we might need it in Ctrl AA by various reasons.
What is the right way to implement all this? At this stage we added the functionality in Ctrl A and call it through event but I think it's not the proper way to do it especially in the cases when event is emitted and the handler is actually not yet properly initialised.

All ideas are welcome.
Thanks in advance

Tandon, Rishi

unread,
Oct 29, 2015, 10:17:37 AM10/29/15
to ang...@googlegroups.com
You might want to try:
Directive for re-usuable template & behavior and/or
Service for sharing data or reusable utility. 

You can invoke APIs based on pubsub notification ($on, $emit, $braodcast) 


--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.



--
Rishi Tandon
Pearson Learning Technology Group

Mobile: (310) 926-9032

Pearson
Always Learning
Learn more at www.pearson.com

Boyan Djumakov

unread,
Oct 29, 2015, 10:32:44 AM10/29/15
to ang...@googlegroups.com
I'm not sure if my question would be stupid, but wouldn't adding a directive several times in the site, actually bring possibility for a mess as the code of the directive template would exist several times?

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/79G5jMar4wo/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.

Tandon, Rishi

unread,
Oct 29, 2015, 10:37:03 AM10/29/15
to ang...@googlegroups.com
If you are using a proper modular based architecture then based on a template/ view, a particular module would be injected.
And to be specific to your question, directive template would not exist several times :)

Reply all
Reply to author
Forward
0 new messages