如何在表中使用与输入占位符ngFor Angular2
问题描述:
我有一个数组如何在表中使用与输入占位符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'];
我想这个代码
<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到输入我没有得到我的结果...我该如何解决这个问题?
答
这不是超我清楚你想什么来实现,但你可以尝试:
<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>
第二个是正是我需要的,谢谢! –