New Tutorial - Communicating Between Controllers

2,537 views
Skip to first unread message

Lukas Ruebbelke

unread,
May 30, 2012, 4:18:58 PM5/30/12
to ang...@googlegroups.com
Here is a new screencast I just did on communication between two controllers using a shared service and $rootScope.


Wrapping my mind around this really opened up the door on how to build apps with increasing complexity.  

As always, feedback is welcome!

xrd

unread,
May 31, 2012, 7:35:54 AM5/31/12
to ang...@googlegroups.com
Lukas,

I learned a lot, thanks for putting this together.

What I liked:  really great explanation of services and how to broadcast events.  I think you've taken the very technical explanation of services from the documentation and turned it into a tangible and clear use case with a lot of power.  

Chris

Ali

unread,
May 31, 2012, 11:02:53 AM5/31/12
to ang...@googlegroups.com
Thanks, I found it very helpful!


Lukas Ruebbelke

unread,
Jun 1, 2012, 10:20:58 AM6/1/12
to ang...@googlegroups.com
Hey Evgeny - 

I really like your example!

The reason why I stored the value in the service is to allow some kind of business logic to be performed on that value.  ie call a REST service and do something with the result etc and then broadcast the modified value out.

For a straight pass through, I prefer your example over mine.

I admit my example was a little contrived for illustration purposes and could definitely be refined. With that said, thanks for the fiddle! I love the feedback and always learn a ton!

On Thursday, May 31, 2012 3:15:14 PM UTC-7, Evgeny Shepelyuk wrote:
Sorry, link to the latest version http://jsfiddle.net/eshepelyuk/vhKfq/

Середа, 30 травня 2012 р. 23:18:58 UTC+3 користувач Lukas Ruebbelke написав:

Eric Terpstra

unread,
Sep 13, 2012, 12:44:20 PM9/13/12
to ang...@googlegroups.com
@ThomasBurleson - MessagingService.js is pretty excellent.  Have you thought about fleshing this out more, or at least putting it on gitHub?

On Thursday, June 7, 2012 11:46:28 AM UTC-5, ThomasBurleson wrote:
Lukas,

Thanks for the video.
You and I discussed this offline and I thought I woud post for the AngularJS community.

Use $scope to message [using $emit() or $broadcast()] across controllers works only for Controllers. Using a sharedService may be too heavyweight.

Better yet would be the use of a Publish/Subscribe mechanism [aka MessageQueue]. I created a MessageQueue mechanism that is published like an EventDispatcher.
So any object can have the EventDispatcher inject and use that to listen to all publishers or dispatch/announce on that queue [event type], 

I have decided to blog/screencast about Publish/Subscribe and EventDispatcher solutions in AngularJS. 
Meanwhile, here is a revised jsFiddlehttp://jsfiddle.net/ThomasBurleson/sv7D5/.

The AngularJS app MessagingDemo uses injected EventDispatchers instances to create specific publish/subscribe message queues. 
  1. Notice that the app also uses a reusable Angular.module called `messaging`. 
  2. Notice how the MessagingDemo requires the `messaging` module:   angular.module('MessagingDemo', ['messaging']); 
For Flex developers the EventDispatcher approach will seem very familiar. 
And I think the Publish/Subscribe service code [used within the above jsFiddle] is very valuable for AngularJS developers:  MessagingService.js
.

- ThomasB
Reply all
Reply to author
Forward
0 new messages