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"/>
1 Answer 1
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.
-
\$\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 modelbooking.type
as it's inside another scope, created byNSPopover
and angular modal. How to change that? \$\endgroup\$vickk– vickk2015年05月18日 08:58:29 +00:00Commented May 18, 2015 at 8:58 -
\$\begingroup\$ @vickk You can either used shared services (preferred) or events. \$\endgroup\$Dmitri Zaitsev– Dmitri Zaitsev2015年05月18日 13:49:30 +00:00Commented May 18, 2015 at 13:49