簡體   English   中英

Ionic 3 和 Angular 2 中的多個 @Input

[英]Multiple @Input in Ionic 3 and Angular 2

在我的 Ionic 3 項目中,我創建了自定義組件 my-component。 現在我們知道使用 angular @Input 我們可以將數據傳遞給這個組件。 我有 2 個輸入作為

  @Input('finder') myFinder: Finder; //Finder is an Interface
  @Input('list') myList: Array<any>; 

我使用這個組件作為

<my-component [finder]="dataFinder" [list]="aList"></my-component>

這兩個dataFinderaList具有價值,但myFinder值總是undefined ,其中myList正確填充。

這是使用多個輸入的任何限制嗎?

實際上,您根本不需要維護 2 個數據綁定屬性。 您可以更優雅地進行操作,如下所示。 希望代碼是不言自明的。

我的類.ts

export class MyClass{
   finder:Finder;
   myList:Array<any>;   
}

.ts

@Input('data') data: MyClass;

.html

<my-component [data]="data"></my-component>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM