0

I'm fairly new to AngularJS and trying to learn by doing.

There is a function in a directive I'm looking to access from the view. What I have in my HTML file is

<div collapse class="collapsed" ng-click="toggle()" ></div>

What's going on there is the toggle() function should be called on click and change the class to expanded, effectively changing the background image described in the CSS. toggle() is inside the collapse directive.

It doesn't seem to be accessing it though and I'm not sure why. Is there another way to do this or actually access said directive from the view? Could you explain why it's not accessing it?

Jesse Samson
  • 133
  • 1
  • 12
  • 1
    toggle() needs to be on the scope of your directive. Either assigned, for example, in the link function of the directive or in your controller. $scope.toggle = function(){...} – Craig Squire Mar 04 '14 at 21:56

1 Answers1

0

Could this question possibly help? 15672709, it leads to this fiddle and goes beyond in case you nest your directives like below:

<div ng-controller="MyCtrl">
  <div screen>
    <div component>
        <div widget>
            <button ng-click="widgetIt()">Woo Hoo</button>
        </div>
    </div>
  </div>
</div>
Community
  • 1
  • 1
mindandmedia
  • 6,800
  • 1
  • 24
  • 33