How to call angular javascript directive methods from the global scope
- by user1659278
I have a directive like the one of the examples from AngularJS, shown below.
How can I call the toggle method from the global scope?
I want to be able to toggle the zippy from some legacy code.
myApp.directive('zippy',
function(){
return {
restrict: 'E',
replace: true,
transclude: true,
scope: { title:'bind' },
template:
'<div class="zippy">' +
'<div class="title">{{title}}</div>' +
'<div class="body" ng-transclude></div>' +
'</div>',
link: function(scope, element, attrs) {
var title = angular.element(element.children()[0]),
opened = true;
title.bind('click', toggle);
function toggle() {
opened = !opened;
element.removeClass(opened ? 'closed' : 'opened');
element.addClass(opened ? 'opened' : 'closed');
}
toggle();
}
}
});