Skip to content

Instantly share code, notes, and snippets.

@marlun78
Created November 20, 2015 14:19
Show Gist options
  • Save marlun78/2aa5dac4607d30ad145d to your computer and use it in GitHub Desktop.
Save marlun78/2aa5dac4607d30ad145d to your computer and use it in GitHub Desktop.
A set of directives that works with ngRepeate
angular.module('me.repeat', [])
.directive('meRepeat', repeatDirective)
.directive('meRepeateven', repeatEvenDirective)
.directive('meRepeatodd', repeatOddDirective)
.directive('meRepeatstart', repeatStartDirective)
.directive('meRepeatmiddle', repeatMiddleDirective)
.directive('meRepeatend', repeatEndDirective);
function repeatDirective() {
return function (scope, element, attrs) {
scope.$eval(attrs.meRepeat);
};
}
function repeatEvenDirective() {
return function (scope, element, attrs) {
if (scope.$even) {
scope.$eval(attrs.meRepeateven);
}
};
}
function repeatOddDirective() {
return function (scope, element, attrs) {
if (scope.$odd) {
scope.$eval(attrs.meRepeatodd);
}
};
}
function repeatStartDirective() {
return function (scope, element, attrs) {
if (scope.$first) {
scope.$eval(attrs.meRepeatstart);
}
};
}
function repeatMiddleDirective() {
return function (scope, element, attrs) {
if (scope.$middle) {
scope.$eval(attrs.meRepeatmiddle);
}
};
}
function repeatEndDirective() {
return function (scope, element, attrs) {
if (scope.$last) {
scope.$eval(attrs.meRepeatend);
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment