How can I create a generic component in Angular 2/Typescript that is capable of creating an instance of the generic-type?
@Component({
selector: 'generic',
template: 'generic.html'
})
export class GenericComponent<T> {
private array: T[];
addElement() {
const object = new T();
this.array.push(object);
}
}
Currently I get an error message saying:
TS2693: 'T' only refers to a type, but is being used as a value here.
Furthermore, I should be able to specify the type somehow:
<generic ...></generic>