Created
January 27, 2015 13:06
-
-
Save geovanisouza92/24d9eafc70e9f4b1978b to your computer and use it in GitHub Desktop.
Angular.js sample directive
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
| angular.module('myApp') | |
| .directive('orderRequirement', orderRequirement); | |
| /* @ngInject */ | |
| function orderRequirement() { | |
| var directive = { | |
| restrict: 'EA', // Restrict to [E]lement or [A]ttribute | |
| templateUrl: 'partials/requirements-order-requirement.html', // HTML template | |
| scope: { // Isolated scope, defining the tag attributes that binds to scope variables | |
| orders: '=', | |
| filter: '=', | |
| }, | |
| link: linkFn, | |
| }; | |
| function linkFn(scope, element, attrs) { | |
| // Additional logic, $http/$resource requests, etc. | |
| } | |
| return directive; | |
| } |
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
| <tr ng-repeat="(c, v) in r.col"> <!-- r.col is an object --> | |
| <td> | |
| <!-- order-requirement is the custom directive --> | |
| <order-requirement orders="v.siz['P'] || v.siz['36'] || {}" filter="state.search"></order-requirement> <!-- v.siz is another object --> | |
| </td> | |
| </tr> |
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
| <span> | |
| <strong>{{orders.qty}}</strong> <!-- orders is an attribute on custom directive and a variable of scope --> | |
| <br> | |
| </span> | |
| <span ng-repeat="c in orders.cut"> | |
| <span ng-bind-html="c | highlight:filter"></span> <!-- highlight is a custom filter, just ignore --> | |
| <br> | |
| </span> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment