I have a number of angular 1.5 components that all take the same attributes and data structure. I think they could be re-factored into a single component, but I need a way to dy
This is not something that components were specially made for. The task narrows down to using a directive with dynamic templates. The existing one is ng-include
.
To use it within a component, it should be:
var myComponentDef = {
bindings: {
type: '<'
},
template: '',
controller: function () {
this.$onChanges = (changes) => {
if (changes.type && this.type) {
this.templateUrl = this.type + '.html';
}
}
}
}