2017-12-28 13 views
0

テーブルがngForで作成されていますが、tdの1つに説明を入力できる入力がありますが、最初に説明を入力すると例えば、それらのすべてが同じ値を得る。角2+ [(ngModel)]倍の入力で同じ値を得る場合

// Only simulation, because I will get the values from bd, and I can change the value and save on bd again. 
 

 
public description = ['teste1', 'teste2', 'teste3', 'teste4', 'teste5']; 
 
<tr *ngFor="let peopleSkill of people.peopleSkills;"> 
 

 
... 
 

 
<td> 
 
    <p *ngIf="!editSkill">{{description}}</p> 
 
    <input *ngIf="editSkill" type="text" [(ngModel)]="description" placeholder="Digite a descrição"> 
 
</td> 
 

 
... 
 
</tr>

UPDATE:それは今働いている

= D

public descriptions: string[] = [ 
 
    'Teste1', 
 
    'Teste2', 
 
    'Teste3', 
 
    'Teste4', 
 
    'Teste5' 
 
    ]; 
 

 
<tr *ngFor="let peopleSkill of people.peopleSkills; let description of descriptions; let i=index;"> 
 
... 
 
<p *ngIf="!editSkill">{{descriptions[i]}}</p> 
 
       <input *ngIf="editSkill" type="text" [(ngModel)]="descriptions[i]" placeholder="Digite a descrição" > 
 
       ... 
 
</tr>

+1

以下のコードでこの問題を解決してきました。配列の説明を作成し、ループの各パスにユニークなインデックスを使用してください –

+0

@DeepakKumarTP Tks、私は試してみます... – ESC

+1

[(ngModel)] = "description"が間違っています。 – kriss

答えて

0

私はあなたがすべてのループを介して同じ説明変数を使用している

public descriptions: string[] = [ 
 
    'Teste1', 
 
    'Teste2', 
 
    'Teste3', 
 
    'Teste4', 
 
    'Teste5' 
 
    ]; 
 

 
<tr *ngFor="let peopleSkill of people.peopleSkills; let description of descriptions; let i=index;"> 
 
... 
 
<p *ngIf="!editSkill">{{descriptions[i]}}</p> 
 
       <input *ngIf="editSkill" type="text" [(ngModel)]="descriptions[i]" placeholder="Digite a descrição" > 
 
       ... 
 
</tr>

関連する問題