Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Normally the way you access a parent scope variable in a directive is through bi-directional binding (<code>scope:{model:'=model'}</code> - see <a href="http://docs.angularjs.org/guide/directive">the angular guide on directives</a>) in the directive configuration), but since you're using transclusion this is not so straight forward. If the child directive will always be a child of the parent directive you can however configure it to require the parent, and then get access to the parent controller in the child link function:</p> <pre class="lang-js prettyprint-override"><code>myApp.directive('parent', function() { return { scope: true, transclude: true, restrict: 'EA', template: '&lt;div ng-transclude&gt;&lt;h1&gt;I\'m parent {{obj.prop}}&lt;h1&gt;&lt;/div&gt;', controller: function($scope) { $scope.SOME_CONST = 'someConst'; this.SOME_CONST = $scope.SOME_CONST; } } }); myApp.directive('child', function() { return { restrict: 'EA', require:'^parent', scope:true, link:function(scope,element,attrs,parentCtrl){ scope.SOME_CONST = parentCtrl.SOME_CONST; }, template: '&lt;h1&gt;I\'m child.... I want to access my parent\'s stuff, but I can\'t. I can access MyCtrlScope though, see &lt;b&gt;{{obj.prop}}&lt;/b&gt;&lt;/h1&gt; how can I access the &lt;b&gt;SOME_CONST&lt;/b&gt; value in my parent\'s link function? is this even a good idea? {{SOME_CONST}}. I really don\'t want to put everything inside the MyCtrl', } }); </code></pre> <p>See this update: <a href="http://jsfiddle.net/uN2uv/">http://jsfiddle.net/uN2uv/</a></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload