假设我有一个具有固定输入参数类型的组件,
@Component({
selector: 'fixed',
template: '<div>{{value}}</div>'
})
export class FixedComponent {
@Input() value: string;
}
我如何着手使该参数类型通用,即
@Component({
selector: 'generic',
template: '<div>{{value}}</div>'
})
export class GenericComponent<T> {
@Input() value: T;
}
即父组件的模板中的类型如何传递?
<generic ...></generic>
最佳答案
似乎在使用 AOT compilation 时唯一的方法是用“any”替换通用类型。参见 https://github.com/angular/angular/issues/11057
关于angular - 如何将泛型类型参数传递给 Angular2 组件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37235170/