带有构造函数参数的 Nativescript registerElement



谁能帮我注册元素? 我正在尝试注册一个在构造函数中具有服务的元素。 我有以下代码:

export class CardComponent extends ContentView implements OnInit{
  constructor(private componentFactoryResolver: ComponentFactoryResolver) {
    super();
  }
...
}
registerElement('app-card', () => CardComponent);

我收到错误error TS2322: Type 'typeof CardComponent' is not assignable to type 'ViewClass'.

>registerElement被指定用于NativeScript UI元素,任何可能从基View或其任何后代(如ContentView(扩展的内容。

但是这些 UI 元素不能有 Angular 的生命周期钩子或依赖注入。我认为您正在尝试将它们混为一谈,这是不可能的。

如果您愿意为自定义 UI 元素提供广泛的 Angular 支持,则应编写一个单独的 Angular 组件,该组件可能会继承自定义 UI 元素。类似于RadListView vs RadListViewComponent的东西。

最新更新