My example is superficial, the short of it I'm trying to access the parent data of the current scope of what I have:
I have a bunch of tasks I'm watching. I need to watch on when task.data changes
<div ng-repeat='task in tasks'>
<input type='checkbox' ng-model='task.data' />
</div>
but I need to update the task based on its id, so I was thinking something like child.$parent
exp = 'tasks.task[0].data'
$scope.$watch exp, (old_val,new_val,child)=>
if new_value is 'something'
id = child.$parent.id
@MyService.do_stuff id
You shouldn't be trying to access the parent scope in most cases. In your case, I'm not sure why you'd want to. If you just need to react to a change, why not something like this:
$scope.checkTask = function( id ) {
MyService.do( id )
};
<div ng-repeat="task in tasks">
<input type="checkbox" ng-model="task.data" ng-change="checkTask(task.id)" />
</div>