Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

what does $parent mean in AngularJS?

Tags:

angularjs

I am completely new to AngularJS. In the code I am supposed to add a feature to I can see $scope.$parent I know about $scope. I also know that when I see a $ it means it is built-in angular. So I searched for it in Angular web site but I did not have any luck finding anything about $Parent as a built-in service or factory or directive, etc... Can anybody help me understand what it means. Also how I can get to an answer in their documentation when I run into something new?

like image 1000
Maryam Avatar asked Jan 27 '16 00:01

Maryam


1 Answers

The documentation for $parent is sparse, but you can find it referenced here at the very bottom of the page.

$scope.$parent refers to the $scope of the parent element. E.g. if you have an element with a controller nested within another element with it's own controller:

<div ng-controller="parentController">
  ... something in the parent element
  <div ng-controller="childController">
     ... something in the child element
  </div>
</div>

You can access variables attached to the parentController from the childController using $scope.$parent. and use them in the child element.

like image 99
Patrick Shaughnessy Avatar answered Nov 14 '22 22:11

Patrick Shaughnessy