1

I am trying to build a responsive data table using Angular with a directive and ng-repeat. I have managed to get the ng-repeat to work with tables: http://jsfiddle.net/raff77/Asb8k/

{}

I am now trying to get it to work with a directive and the ng-repeat does not work. http://jsfiddle.net/raff77/uwGXb/3/

{}

Is there a way to get the ng-repeat to work with your directive or should you build that into your directive. Notice I have built out a solution to add the rows as strings then html but i want to avoid this and do things the Angular way.

2 Answers 2

3

You are creating a new scope in the directive as shown here

scope: { gbsdata: '=' },

But "chartdata" is the array you were watching, which is not available in this scope.

scope.$watch("chartdata", function (chartdata) {

Check this fiddle it will help you. http://jsfiddle.net/KLGrV/1/

Sign up to request clarification or add additional context in comments.

1 Comment

Ahh yes thats a typo but that was me trying to convert the code I had written for locally
2

There seems to be a bug in AngularJS when you want to put 'td's into a table in a directive. See this question Angular Directive Does Not Evaluate Inside ng-repeat and particularly this answer: https://stackoverflow.com/a/15755234/669561. https://github.com/angular/angular.js/issues/1459

And I don't really see, why you want to fill up the table with a directive. Your first approach without the table seems to work perfectly fine and I cannot see any advanteges over using directives.

4 Comments

Hi DanEEStar, i want to build a directive that takes the definition of a table head and some parameters, like sort, search, pagination and automatically build a widget. This was just the first step. I read those posts and believe I need to build a compile function into my directive and build out the ng-repeat in there. I will also have to add filters etc. Thanks for your time.
The grid seems to perform poorly but thanks, will look into the code and look at building or extending.
As a matter of interest, where should you manipulate the template when writing directives. I want to define the head of my table for a grid and have the directive build out a template before linking.
Found that, I should manipulate the DOM template in the compile function but in the link functions.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.