I would like to hear your thoughts as Angular developers on two approaches
for making configurable components.
Approach 1: Configuration Object
Let's think of ui-grid like library to display a table for some raw data
supplied by a host component.
It has this kind of host template:
<my-magic-table [table-config="configJson" [data]="rawData" />
And then in our component we'll have to expose `configJson`, something like
class MyComponent {
private configJson = {
columnDefs: [
{name: "col1", field: "0"},
{name: "col2", field: "data.selector"}
],
someOtherConfig: "specialValue"
}
...
}
Approach 2: ContentChildren
The other approach is to move as much configurations as we can into the
template by using ContentChildren. Our host template will be:
<my-magic-table [someOtherConfig]="'specialValue'" [data]="rawData">
<my-magic-column [selector]="'0'">
<my-magic-header>col1</my-magic-header>
</my-magic-column>
<my-magic-column [selector]="'data.selector'">
<my-magic-header>col2</my-magic-header>
</my-magic-column>
</my-magic-table>
In this approach my host component only needs to expose `rawData` and has
no inner configuration object.
Which approach do you prefer? Which feels more angular2-like to you? What
pros and cons do you find for each approach?
Thank you!
--
You received this message because you are subscribed to the Google Groups
"Angular" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.