Created
March 26, 2016 17:26
-
-
Save marcoszf/5e2c14eb43bf2f972b16 to your computer and use it in GitHub Desktop.
Angularjs Directives - EXEMPLOS Básico - Referência
This file contains hidden or 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
| //Reference: http://ng-learn.org/2014/01/Dom-Manipulations/ | |
| // Here we create a module to group these directives jquery related | |
| var jqueryDirectives = angular.module("jqueryDirectives", []); | |
| // Here we add a directive to the module. camelCase naming in this file (mySlide) and dash separated in html (my-Slide) | |
| jqueryDirectives.directive("mySlide", [ | |
| function() { | |
| return { | |
| // This means the directive can be used as an attribute only. Example <div data-my-slide="variable"> </div> | |
| restrict: "A", | |
| // This is the functions that gets executed after Angular has compiled the html | |
| link: function(scope, element, attrs) { | |
| // We dont want to abuse on watch but here it is critical to determine if the parameter has changed. | |
| scope.$watch(attrs.mySlide, function(newValue, oldValue) { | |
| // This is our logic. If parameter is true slideDown otherwise slideUp. | |
| // TODO: This should be transformed into css transition or angular animator if IE family supports it | |
| if (newValue) { | |
| return element.slideDown(); | |
| } else { | |
| return element.slideUp(); | |
| } | |
| }); | |
| } | |
| }; | |
| } | |
| ]); | |
| <div class="search-details-form" data-my-slide="showRedoSearchDetails"> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment