带有构造函数参数的Nativescript registerElement

问题描述 投票:0回答:1

有人可以帮我注册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'.

nativescript angular2-nativescript
1个回答
1
投票

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

但是这些UI元素不能具有Angular的生命周期钩子或依赖注入。我认为你试图将它们混合在一起是不可能的。

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

© www.soinside.com 2019 - 2024. All rights reserved.