Skip to content

Instantly share code, notes, and snippets.

@simonjodet
Last active August 29, 2015 14:02
Show Gist options
  • Save simonjodet/db6c187d0903c7491b87 to your computer and use it in GitHub Desktop.
Save simonjodet/db6c187d0903c7491b87 to your computer and use it in GitHub Desktop.
Angular directive to have an element toggle another element's display on click
'use strict';
angular.module('myApp').directive(
'ngToggle',
function() {
var factory = {
restrict: 'A',
link: function postLink(scope, element, attributes) {
$(element).on('click', function(event) {
event.preventDefault();
$('#' + attributes.ngToggle).toggle(0);
});
}
};
return factory;
}
);
<a href="" ng-toggle="panel">Toggle panel</a>
<div id="panel" style="display:none;">My Panel</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment