0

Currently I have a preview list component which displays a list of preview components from array data:

<preview-list previews="previewsArray"></preview-list>

The problem here is that I have to build a new list component for every page instead of just plugging in components and data. Is there a way to generalize the preview list component so that I can display arbitrary lists of components? In a manner similar to this:

<component-list list="previewsArray component="preview"></component-list>
NickG
  • 138
  • 1
  • 12
  • 1
    I don't know about a generic, but a possible solution to this would be using [`ng-switch`](https://docs.angularjs.org/api/ng/directive/ngSwitch). You would have to create a new case every time you wanted to add a new possible component type to `component-list`, but it would be one line, and probably pretty easy to manage. – mhodges Jul 28 '17 at 17:22
  • Another option is to add templates to the templateCache and `ng-include`, like demonstrated in [this stack answer](https://stackoverflow.com/a/40640326/498719) – mhodges Jul 28 '17 at 17:27

1 Answers1

1

It may look like that : Insert directive programmatically angular

This is a hard way but I see nothing else.

Related doc: https://docs.angularjs.org/api/ng/service/$compile#!

Optionnal doc: https://docs.angularjs.org/api/auto/service/$injector

HollyPony
  • 817
  • 9
  • 15