-
Notifications
You must be signed in to change notification settings - Fork 851
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(ngTableColumnsBinding): new directive that provide access to the…
… $columns array This allows the $columns array to be accessed outside of the html table markup
- Loading branch information
1 parent
7d2965c
commit e290293
Showing
2 changed files
with
44 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/** | ||
* ngTable: Table + Angular JS | ||
* | ||
* @author Vitalii Savchuk <[email protected]> | ||
* @url https://github.com/esvit/ng-table/ | ||
* @license New BSD License <http://creativecommons.org/licenses/BSD/> | ||
*/ | ||
|
||
(function(){ | ||
'use strict'; | ||
|
||
angular.module('ngTable') | ||
.directive('ngTableColumnsBinding', ngTableColumnsBinding); | ||
|
||
ngTableColumnsBinding.$inject = ["$parse"]; | ||
|
||
/** | ||
* @ngdoc service | ||
* @name ngTableColumnsBinding | ||
* @description One-way data binds the $columns array generated by ngTable/ngTableDynamic to the specified | ||
* expression. | ||
* | ||
* This allows the $columns array to be accessed outside of the html table markup | ||
*/ | ||
function ngTableColumnsBinding($parse){ | ||
var directive = { | ||
restrict: 'A', | ||
require: 'ngTable', | ||
link: linkFn | ||
}; | ||
return directive; | ||
|
||
function linkFn($scope, $element, $attrs){ | ||
var setter = $parse($attrs.ngTableColumnsBinding).assign; | ||
if (setter){ | ||
$scope.$watch('$columns', function(newColumns){ | ||
var shallowClone = (newColumns || []).slice(0); | ||
setter($scope, shallowClone); | ||
}); | ||
} | ||
} | ||
} | ||
})(); |