Skip to content

Instantly share code, notes, and snippets.

@geovanisouza92
Created January 27, 2015 13:06
Show Gist options
  • Select an option

  • Save geovanisouza92/24d9eafc70e9f4b1978b to your computer and use it in GitHub Desktop.

Select an option

Save geovanisouza92/24d9eafc70e9f4b1978b to your computer and use it in GitHub Desktop.
Angular.js sample directive
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;
}
<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>
<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