Avoid $parent.$parent?
For question on SO: http://stackoverflow.com/questions/35023867/proper-method-to-handle-angular-scope-instead-of-parent-parent/35024387#35024387
by Ryan
HTML
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.1.5/angular.js"></script>
<div ng-app="MyApp" ng-controller="MyCtrl">
<div ng-if="showOnCondition">
<label ng-repeat="item in repeatingItems">
{{item}}
<setting settings="settings" item="item" />
</label>
</div>
<pre>
{{checkSetting()}}
</pre>
</div>
JavaScript
var myApp = angular.module('MyApp', []);
myApp.controller('MyCtrl', function($scope) {
$scope.settings = {
someProperty: '',
anotherProperty: 'Hello'
};
$scope.repeatingItems = [
'One',
'Two',
'Three'
];
$scope.showOnCondition = true;
$scope.checkSetting = function() {
// When calling checkSettings(), I would like to access the value of someProperty here
return $scope.settings;
}
});
myApp.directive('setting', function() {
return {
restrict: 'E',
template: '<input type="radio" ng-model="settings.someProperty" ng-value="item" name="mySetting" />',
scope: {
settings: '=',
item: '='
}
};
});