2017-07-25 90 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

第二个是正是我需要的,谢谢! –