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"/>
Jamal
35.2k13 gold badges134 silver badges238 bronze badges
asked May 15, 2015 at 15:07
\$\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.

answered May 17, 2015 at 3:17
\$\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\$ 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

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.