、その私のhtmlファイル:削除オブジェクト(角2)
button type="submit" (click)="addAnotherLanguague()" >Add non native languague</button>
<li *ngFor="let languague of listOfLanguagues;">
<div class="form-item form-item--text">
<label class="label invisible">Years studied</label>
<input type="number" min="0" [(ngModel)]="languague.yearsStudied" name="years" placeholder="Years studied"/>
</div>
<button type="submit" (click)="removeLanguague(languague)" >Remove</button> // here you can see use of method
</li>
そして、そこです私はこれを下回るまさにこのlanguagueを削除するためcomponent.ts
(...)
this.listOfLanguagues = new Array <LanguagueInformationData>();
}
addAnotherLanguague(){
this.listOfLanguagues.push(new LanguagueInformationData);
}
removeLanguague(languague){
this.listOfLanguagues.slice(this.listOfLanguagues.indexOf(languague), 1);
}
(...)
うまく機能を追加し、私は削除し、まだそのlanguagueの参照を転送する方法を知らないためにすべてを試してみましたが、私は、.pop使用したくありませんボタン。 私を助けることができますか?
[編集] 新しいコードを追加しようとするたびに、配列に存在するクラスのデータがクリアされるため、このコードでもう一度問題が発生しました。
[角度2の格納された配列からアイテムを削除]可能な複製(https://stackoverflow.com/questions/40462369/remove-item-from-stored-array-in-angular-2) – PierreDuc
私は編集しました少し私の質問、新しい問題の原因 –