Passing a Template to a Directive

44 views
Skip to first unread message

Daniel Duckworth

unread,
Apr 21, 2014, 6:38:53 PM4/21/14
to ang...@googlegroups.com

Hi all,

I am writing in reference to this StackOverflow post. The general idea is that I would like to write a tabular directive that generates a <table>...</table>, where the contents of each cell are based on (1) the data relevant to that cell, (2) an angular template passed via attributes to the tabular directive, and (3) context available in the $scope of the controller _outside of the tabular directive.

For example, take this JSFiddle. I define a template containing a country directive and an array of country ids to the tabulate directive. Each country corresponds to one <tr> element, which I would like to contain the template rendered with {{ flags }} taken from myController and {{ cellData }} somehow passed via tabulate.

Short of pairing the country directive with a service, is there a way I can get this functionality?

Thanks!

Gabriel Aszalos

unread,
Apr 23, 2014, 5:13:14 AM4/23/14
to ang...@googlegroups.com
You're doing it wrong bro, please consider looking into "Best practices", "AngularJS Anti-patterns" and possibly directive priority for your specific case. Please do not pass templates through attributes, and do not put them on the scope.

Daniel Duckworth

unread,
Apr 24, 2014, 1:53:23 PM4/24/14
to ang...@googlegroups.com
I realize now what I'm asking for is more or less `ng-repeat`, but with a bit more structure. I'll just read the source code for that directive and generalize appropriately.

Gabriel Aszalos

unread,
Apr 24, 2014, 1:58:40 PM4/24/14
to ang...@googlegroups.com
If you really need to save the template somewhere use $templateCache


On Thursday, 24 April 2014, Daniel Duckworth <d...@premise.com> wrote:
I realize now what I'm asking for is more or less `ng-repeat`, but with a bit more structure. I'll just read the source code for that directive and generalize appropriately.

On Wednesday, April 23, 2014 2:13:14 AM UTC-7, Gabriel Aszalos wrote:
You're doing it wrong bro, please consider looking into "Best practices", "AngularJS Anti-patterns" and possibly directive priority for your specific case. Please do not pass templates through attributes, and do not put them on the scope.

On Monday, 21 April 2014 23:38:53 UTC+1, Daniel Duckworth wrote:

Hi all,

I am writing in reference to this StackOverflow post. The general idea is that I would like to write a tabular directive that generates a <table>...</table>, where the contents of each cell are based on (1) the data relevant to that cell, (2) an angular template passed via attributes to the tabular directive, and (3) context available in the $scope of the controller _outside of the tabular directive.

For example, take this JSFiddle. I define a template containing a country directive and an array of country ids to the tabulate directive. Each country corresponds to one <tr> element, which I would like to contain the template rendered with {{ flags }} taken from myControl

--
You received this message because you are subscribed to a topic in the Google Groups "AngularJS" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/angular/lBPXj3CPfU8/unsubscribe.
To unsubscribe from this group and all its topics, send an email to angular+u...@googlegroups.com.
To post to this group, send email to ang...@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages