I'm trying to implement inline editing using ngModel in Angular2. I have an array which needs to be iterated using ngFor and also uses ngModel. When i try to apply inline editing for this array, i can only edit one character for each of the array's variables.
You can find a working example here.
Here's the code for the component where i'm using ngModel and ngFor together:
import {Component} from '@angular/core'
import {InlineEditComponent} from './inline.component';
@Component({
selector: 'inline-app',
providers: [],
template: `
<div>
<h2>Inline Editing with Angular 2</h2>
<inline-edit [(ngModel)]="editableText" (onSave)="saveEditable($event)"></inline-edit>
</div>
<div>
<ul style="margin:5px;">
<li ngFor #arr [ngForOf]="array" [ngForTrackBy]="customTrackBy">
<inline-edit [(ngModel)]="arr" (onSave)="saveEditable($event)"></inline-edit>
</li>
// <li style="margin:5px;" *ngFor="let arr of array ; let i=index">
// <inline-edit [(ngModel)]="array[i]" (onSave)="saveEditable($event)"></inline-edit>
// </li>
</ul>
</div>
`,
directives: [InlineEditComponent]
})
export class InlineApp {
customTrackBy(index: number, obj: any): any {
return index;
}
editableText = "Click to edit me!";
// Save name to the server here.
saveEditable(value){
console.log(value);
}
array=['bmw','benz','honda'];
}
If anyone could help me, it would be great.