Skip to content

Commit

Permalink
feat(ngTableController): add function to parse the expression used to…
Browse files Browse the repository at this point in the history
… initialise ngTableDynamic

This is useful to support integration's with directives that extend the ngTable/ngTableDynamic directive
  • Loading branch information
ccrowhurstram committed Jul 20, 2015
1 parent a4ce6f8 commit e9333f9
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
12 changes: 12 additions & 0 deletions src/scripts/04-controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,18 @@ function($scope, NgTableParams, $timeout, $parse, $compile, $attrs, $element, ng
})
};

this.parseNgTableDynamicExpr = function (attr) {
if (!attr || attr.indexOf(" with ") > -1) {
var parts = attr.split(/\s+with\s+/);
return {
tableParams: parts[0],
columns: parts[1]
};
} else {
throw new Error('Parse error (expected example: ng-table-dynamic=\'tableParams with cols\')');
}
};

this.setupBindingsToInternalScope = function(tableParamsExpr){

// note: this we're setting up watches to simulate angular's isolated scope bindings
Expand Down
14 changes: 1 addition & 13 deletions src/scripts/05-directive.js
Original file line number Diff line number Diff line change
Expand Up @@ -106,18 +106,6 @@ app.directive('ngTable', ['$q', '$parse',
*/
app.directive('ngTableDynamic', ['$parse', function ($parse){

function parseDirectiveExpression(attr) {
if (!attr || attr.indexOf(" with ") > -1) {
var parts = attr.split(/\s+with\s+/);
return {
tableParams: parts[0],
columns: parts[1]
};
} else {
throw new Error('Parse error (expected example: ng-table-dynamic=\'tableParams with cols\')');
}
}

return {
restrict: 'A',
priority: 1001,
Expand Down Expand Up @@ -154,7 +142,7 @@ app.directive('ngTableDynamic', ['$parse', function ($parse){
}
});
return function (scope, element, attrs, controller) {
var expr = parseDirectiveExpression(attrs.ngTableDynamic);
var expr = controller.parseNgTableDynamicExpr(attrs.ngTableDynamic);

controller.setupBindingsToInternalScope(expr.tableParams);
controller.compileDirectiveTemplates();
Expand Down

0 comments on commit e9333f9

Please sign in to comment.