0

I am new to AngularJS, the notion of scopes really confuses me. I have a situation where I want to modify a an object or a variable from different scopes. Here is why: in my application I want to centralize the user notification Controller and notification view. In the middle top of the page. I separate my code as follow: each view has its controller I think its fair reasonable. I want to inject a service or some common object that when invoking its function with some string parameter on a common place but, I figured out that I can not inject $scope service. So, when

2 Answers 2

2

What you want is to communicate between controllers. That is fairly easy to realize whit a service that can broadcast messages (or objects) between controllers.

There is a nice youtube about this:

http://www.youtube.com/watch?v=1OALSkJGsRw

Sign up to request clarification or add additional context in comments.

4 Comments

Thank you I will check it out late but, now its time to go :D
I watched the video. Honestly I don't like the way this communication is made because I have to put $scope.$on('someEvent',function(){}); In every one of my controllers. Moreover changing the name of an event is error prone.
You could also pass $rootScopealong and use common properties and methods in rootScope
I am working on implementing a simple design pattern for this I will post it just in a minute.
0

OK here what I have done in my application. I am a java programmer and I used to work with GWT

In GWT ther is a very nice design pattern, to notify widgets across the application, called EventBus. In angular I tried to do something similar. Here is the code link in gist

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.