Last active
August 29, 2015 14:02
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
'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; | |
} | |
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<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