Hi Everyone,
I have tried with a simple table which is editable.At first I have added values in the text-box however when I add values in a text-box dynamically and hit on Add button ie when I add a new row all the values in the previous text-box(rows) turn blank and I also get an Error saying ExpressionChangeAfterItHasBeenCheckedError.
Please check my below code and also my attachment
HTML Code
<tr>
<th><input type="checkbox" ng-model="selectedAll" ng-click="checkAll()" /></th>
<th>Firstname</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let personalDetail of personalDetails ">
<td>
<input type="checkbox" ng-model="personalDetail.selected"/>
</td>
<td >
<input type="text"
class="form-control"
formControlName="fname"
[(ngModel)]="personalDetail.fname" required/></td>
</tr>
TS file
export class TestComponent implements OnInit {
fname: string
lname: string
email: string
form: FormGroup
public personalDetails: any[]= [
{
'fname':'John',
},
{
'fname':'Roy',
}
];
constructor(fb: FormBuilder,) {
this.form = fb.group({
fname: [''],
})
}
ngOnInit() {
}
addNew(){
console.log('rohit')
console.log(this.personalDetails)
let len = this.personalDetails.length
this.personalDetails.push({
'fname': "",
});
Please could anyone tell me which part of the code should I rectify.
Thanks & Regards ,
Rakhee