user3024827
user3024827

Reputation: 1258

Accessing controller from directive

I have create a custom directive that displays the directive template within the current view:

<div class="upper-outfits-layer" ng-show="outfitExpanded">
    <expanded-outfit outfit="outfits[currentOutfit]"></expanded-outfit>
</div>

That will display an html template. The view this directive is placed within, has its own controller. I need to access the views scope variables from this directive and vice versa.

Is it possible to access a sperate controller from a custom directive?

Upvotes: 0

Views: 44

Answers (2)

Satyajit Shetye
Satyajit Shetye

Reputation: 100

  1. Do not use isolated scope in your directive. You can directly get access your view scope.
  2. (In case of Isolated scope) Pass the variables in the attribute of your directive. They will be accessible to your directive through your isolated scope.
  3. (In case of Isolated scope) Use scope.$parent in your directive to access view scope.

Upvotes: 2

Jarom&#237;r Šetek
Jarom&#237;r Šetek

Reputation: 478

If you don't isolate the directive's scope using scope:{}, you should be able to access parent controller's variables. Maybe add the directive code to your question if the problem persists...

Upvotes: 0

Related Questions