带有构造函数参数的 Nativescript registerElement

Nativescript registerElement with constructor arguments

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

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.