0

I have two ngControllers in one ngApp. I'd like to data bind the model from one controller with another.

Here's an example of my controllers:

  1. ViewUsers: Is a list view of users

  2. UserDetail: Is a detailed view of a single user

When the user clicks on a userRow(model:$scope.users[n]) in ViewUsers, it's calling a global function that creates a new instance of UserDetail.

But I want to send the $scope.users[n] in the constructor of UserDetail or something by reference so any changes to the modelin my UserDetail controller will be reflected in the userRow from the ViewUsers controller.

So for example, when you change the name in the detailed view, it'll be relected in the list view on the side.

Are services the route I need to go? Or $watch?

Any advice would be appreciated, Thanks!

3
  • 1
    Refer great tutorial "AngularJS controller communication" here onehungrymind.com/angularjs-communicating-between-controllers Commented Jan 14, 2014 at 8:50
  • Hmm, thanks for this. Although the problem is that I'm creating a new controller dynamically; not written into the html. Maybe i'll try creating the new controller, then broadcasting via rootscope. Commented Jan 14, 2014 at 9:02
  • It can be another solution, yes Commented Jan 14, 2014 at 9:10

1 Answer 1

1

Another approuch to use scope which is parent for both of your scopes or $rootScope.

Also, see this post - there is an example how to share data between controllers.

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

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.