0

On a page, I have the following structure:

  • layoutController (in the js controller: $scope.currentProject = "" )
    • {{ currentProject.Name }}
    • projectListController - (in the js controller, I populate the value of $scope.currentProject with an object)

The problem is that once I set the new value, {{ currentProject.Name }} remains blank.

What's missing?

4 Answers 4

2

use $parent.value to access the parent controller scope.

Demo: http://plnkr.co/edit/vj0kUoiXEqH9w5OPNhsu?p=preview

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

Comments

1

You should try and default the value to a blank object like this

$scope.currentProject = ""

To

$scope.currentProject = {}

Comments

0

When you define a property in the $scope at a parent level it gets inherited through the prototype chain, if you redefine that property in a child $scope you lose that reference.

So the way to proceed would be in projectListController instead of assigning the object to currentProject you should copy the properties into it. Or assign the object to $scope.$parent.currentProject.

Comments

-1

That is because child controllers create a copy of the parent scope.

In your nested controller, you should inject $rootScope instead of $scope

2 Comments

You don't want to pollute the $rootScope with this, so best to use $parent.
I know. Ideally you want to use directives with isolated scopes but that's not part of the question. Using $parent is very sketchy because you would be binding your projectListController to your layoutController.

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.