Skip to content

Instantly share code, notes, and snippets.

@tolemac
Created February 7, 2017 17:32
Show Gist options
  • Save tolemac/cb3f262a4efe967d5e2886f3fee3ce54 to your computer and use it in GitHub Desktop.
Save tolemac/cb3f262a4efe967d5e2886f3fee3ce54 to your computer and use it in GitHub Desktop.
Angular 2 Visual Inheritance
import {Component} from '@angular/core';
function GridComponent(obj: any) {
let templateMetadata = {
template: `blablablab
<table>
<thead>
<tr>${obj.headerTemplate}</tr>
</thead>
<tbody>
<tr *ngFor="let obj of list">${obj.rowTemplate}</tr>
</tbody>
</table>
blablabla`
}
return Component(Object.Assign(obj, templateMetadata));
}
class GridComponentBase {
// ...
// ...
// ...
}
import {GridComponent, GridComponentBase} from './GridComponent';
@GridComponent({
selector: 'person-grid',
headerTemplate: '<th>Nombre</th><th>Apellidos</th>',
rowTemplate: '<td>obj.name</td><td>obj.surname</td>'
})
class PersonGridComponent extends GridComponentBase {
// ...
// ...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment