0

Is there a way to use a scope resolution operator, like in c++, to use a parent $scope variable instead of the one in the current $scope.

I have two controllers, a Root ctrl and a Settings Ctrl. The Settings Ctrl is the child controller of Root ctrl so inherits it's variables. Both Controllers have a variable named $scope.users. Is there a way I can bypass this $scope.user in the settings ctrl(child controller) and use the one in the root ctrl (parent controller)?

2 Answers 2

1

In your child controller you can access the parent controller variable as

$scope.$parent.users
Sign up to request clarification or add additional context in comments.

Comments

0

In Angular, nested child controllers will automatically inherit scope variables from parent controllers. So in your child controller you could essentially access $scope.someParentVariable. Another alternative would be $scope.parent.someParentVariable.

I've made a quick CodePen to demonstrate.

http://codepen.io/oculusriff/pen/YpKaEW

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.