22 lines
559 B
JavaScript
22 lines
559 B
JavaScript
|
import ngModule from '../module';
|
||
|
|
||
|
/**
|
||
|
* Calls a passed function if is the last element from an ng-repeat.
|
||
|
*
|
||
|
* @attribute {String} onLast - Callback function
|
||
|
* @return {Object} The directive
|
||
|
*/
|
||
|
directive.$inject = ['$parse'];
|
||
|
export function directive($parse) {
|
||
|
return {
|
||
|
restrict: 'A',
|
||
|
link: function($scope, $element, $attrs) {
|
||
|
if ($scope.$last && $attrs.onLast) {
|
||
|
let fn = $parse($attrs.onLast);
|
||
|
fn($scope);
|
||
|
}
|
||
|
}
|
||
|
};
|
||
|
}
|
||
|
ngModule.directive('vnRepeatLast', directive);
|