2017-07-25 42 views
0

我有一個數組如何在表中使用與輸入佔位符ngFor Angular2

public example = [['hallo', 'fruit', 'rose'], ['apple','book']] 

我想打的輸入表,其值取決於哪部分我現在用 http://localhost:4200/app?part=1

http://localhost:4200/app?part=2 

我在組件獲得此信息

this.part = this.activatedRoute.snapshot.queryParams['part']; 

我第一部分Part1 example 以及這樣的輸入表格 enter image description here 如果我有第二部分。

我想這個代碼

 <table> 
//choose 0 or 1 array in example array (this works!) 
     <tr *ngFor="let a of example[part-1]"> 
      <td><input> </td> 
     </tr> 
     </table> 

我的問題是,如果我嘗試插入佔位符或ngFor到輸入我沒有得到我的結果...我該如何解決這個問題?

回答

1

這不是超我清楚你想什麼來實現,但你可以嘗試:

<table> 
    //choose 0 or 1 array in example array (this works!) 
    <tr *ngFor="let a of example[part-1]"> 
     <td><input [placeholder]="a"></td> 
    </tr> 
    </table> 

這將使你的佔位符「你好」,「蘋果」的投入,等等。

如果你想要的是每個輸入只有一個字母的佔位符,然後添加另一* ngFor對TD

<table> 
    //choose 0 or 1 array in example array (this works!) 
    <tr *ngFor="let a of example[part-1]"> 
     <td *ngFor="let b of a.split('')"><input [placeholder]="b"></td> 
    </tr> 
    </table> 
+0

第二個是正是我需要的,謝謝! –