0

I was wondering :

Just as without using controller as syntax , I'd have to do :

<body ng-controller="ParentCtrl">
  <input ng-model="name" /> {{name}}

  <div ng-controller="ChildCtrl">
    <input ng-model="name" /> {{name}} - {{$parent.name}}
  </div>
</body>

And now with the Controller as syntax , I can do :

<body ng-controller="ParentCtrl as parent">
  <input ng-model="parent.name" /> {{parent.name}}

  <div ng-controller="ChildCtrl as child">
    <input ng-model="child.name" /> {{child.name}} - {{parent.name}}
  </div>
</body>

Which is great , but what about the controller itself ?

With the first example , I could do :

....controller('Controller', function($scope) {
   // do something with $parent.$scope...

But now , after using this :

....controller('Controller', function() { //this.mySomething....

Question :

How would I reference the parent ? ( in the alias way!)

I mean , NG come here to help us by using aliases to scope via parent && child ,

But is there any representation to that "help" in the controller ?

2
  • You can still inject $scope when using controller as syntax AFAIK Commented Jan 29, 2014 at 6:57
  • @elclanrs Yes I know I just ask if there are any help aliases in the controller. Commented Jan 29, 2014 at 7:02

1 Answer 1

1

No, there isn't.

The goal of the Controller as ... was to make dealing with models more natural, and to remove all of the mess of dealing with $scope, except when needed.

Models don't really have $parents.

$scope has a parent-$scope.

But if I have a parent Controller as "Bike" and a nested controller "Doorknob"...

Doorknob might have .turn() and .type and .locked, but it doesn't have a "Bike", any more than all "Bike"s have "Doorknobs".

You still have direct-access to the $scope in the controller, so you can add your own inheritance, and build your own links -- you can also still reference other $scope properties in your view...

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.