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\$

1 Answer 1

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\$
2
  • \$\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
    Commented May 18, 2015 at 8:58
  • \$\begingroup\$ @vickk You can either used shared services (preferred) or events. \$\endgroup\$ Commented May 18, 2015 at 13:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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