The ability to reply to discussions is limited to PRO members. Want to join in the discussion? Click here to subscribe now.

Sharing Data Between Controllers

Sharing Data Between Controllers

5:13
If AngularJS Controllers are the glue of an application, how do they communicate and pass data around? This introduction to service factories will shed some light on that question.
Watch this lesson now
Avatar
egghead.io

If AngularJS Controllers are the glue of an application, how do they communicate and pass data around? This introduction to service factories will shed some light on that question.

Avatar
Mark

How would you use this approach with dynamic data?

I have data being added to a collection within the service factory using $http. I'm using one controller to initiate the request and than use $q.defer().resolve() to adjust its $scope, but the second controller that shares the same service doesn't update when the services data changes.

In reply to egghead.io
Avatar
Joel

I'd need to see the code but my guess is that you are completely overwriting the property with a new object. You want to update the object/array and not replace to allow binding to function.

In reply to Mark
Avatar
Elgs

These two controllers are in a parent-child relationship. How about sharing data between two side-by-side controllers?

Avatar
Abdo

To share the greeting service between the controllers, we used the variable name "greeting" in the controller's first argument. Does this not break after js minification? How can we work around this?

Avatar
Abdo

It does break the after minification. This is how you work around it:
.controller('FirstCtrl', ['greeting', function(foo) {
// foo is the greeting service in here
}])

In reply to Abdo
Avatar
John

Check out this lesson on using a build tool to make all your angular code "min safe".

https://egghead.io/lessons/angularjs-using-ng-annotate-for-min-safe-angularjs

In reply to Abdo
Avatar
arpan

What editor are you using?

Avatar
roberto

Hello there, i'm a bit new to Angular. So thank you for these courses :)

So here's a noob question. I'm trying to follow the lectures by also reading the Rout code module to have a deeper understanding:

https://code.angularjs.org/1.4.7/angular-route.js

Inside that code- I can't find: (1) ui-view or (2) ui- sref.

So Where are we getting those two functions from ?

Thanks !

Avatar
rui

I think what you should refer to is angular-ui-router rather than angular-router.

In reply to roberto
Avatar

Where can I find the code for this? The code below the video is not the one thats shown in the video

Avatar
Joel

Where can I find the code for this? The code below the video is not the one thats shown in the video

What you see is what you get!

In reply to
Avatar
mlaksv100

Is that deliberate? to post different version of code below the video?

In reply to Joel
HEY, QUICK QUESTION!
Joel's Head
Why are we asking?