ionic/angular html 来自 singleton/global class 的模板

ionic/angular html template from a singleton/global class

使用 Ionic 3/Angular 5,我有一个名为 Helper 的单例 class,其中包含不同的功能。它还包含 3 个列表对象来为我的应用程序提供服务(应该在全球范围内使用)。

现在我想添加一个 <ion-list *ngFor="let item of itemsList">,但是 itemsList 在 other/singleton class 中,而不是在当前的 class 中。我如何引用它以从助手 class?

中获取值

现在我添加到当前 class 的 .ts:

constructor(public navCtrl: NavController, private helper: Helper) {
    let itemsList = this.helper.itemsList;
}

它可以工作,除了它在 lint 中告诉我,itemsList 没有被使用。其实除了在 HTML.

中显示外,我没有其他用途

我也试过<ion-list *ngFor="let item of this.helper.itemsList">但是没用

谢谢

就像你提到的, 在组件中:

constructor(public navCtrl: NavController, public helper: Helper) {} 

并在模板中:

<ion-list *ngFor="let item of helper.itemsList">