0
\$\begingroup\$

This is how I can access the exact scope value, otherwise it will be $scope.type of local scope.

I am accessing this from the template in NSPopover. NSPopover directive has scope: true.

It's also inside the Angular bootstrap module.

<label ng-class="{selected: $parent.$parent.$parent.type == current.type}" >
    <input type="radio" name="type" ng-value="current.type" ng-change="chooseOption()" ng-model="$parent.$parent.$parent.type"/>
\$\endgroup\$
2
\$\begingroup\$

Using $parent is an anti-pattern and sign of bad architecture. What if you code changes together with your parent chain - it will instantly break your code.

Also, have you thought about how you are going to test it?


To have a clean readable code, you want someone looking at it immediately see the meaning. What is the meaning of this object? -

ng-model = "$parent.$parent.$parent.type"

Would you not rather see

ng-model = "selectedItem"

or something more concrete like

ng-model = "myCar"

Naming something "current" makes me wonder what it is. From your code, I have no idea, so it forces me to spend time on looking around and getting clues, for what should be made clear right up front.

\$\endgroup\$
  • \$\begingroup\$ well, I know it's anti-pattern that's why I am asking. its' the model booking.type. But the problem is that I cannot watch changes of just model booking.type as it's inside another scope, created by NSPopover and angular modal. How to change that? \$\endgroup\$ – vickk May 18 '15 at 8:58
  • \$\begingroup\$ @vickk You can either used shared services (preferred) or events. \$\endgroup\$ – Dmitri Zaitsev May 18 '15 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.