I'm aware with basic 2-way binding in angular 2 as shown in the docs.
I have an array of person
s, which I'm using to build an html list:
Now, when I click on a person's row, I can edit it using 2-way binding:
<form>
<label>Name: </label>
<input [(ngModel)]="selectedPerson.name" name="name"/>
<label>Description: </label>
<input [(ngModel)]="selectedPerson.job" name="job"/>
</form>
Now, what I want is to 2-way bind the list itself: (The list is in a different view than the row editor)
<div class='row' *ngFor="let person of model">
<div class='col'>{{person.name}}</div>
<div class='col'>{{person.job}}</div>
</div>
Currently, I'm using *ngFor
to list out all persons. If my model
is an array of two persons, I get two rows. There are cases when the model
might change to have 3 or 4 persons. Is there any way I can make angular detect this and add rows accordingly? [(ngModel)]
doesn't seem to be applicable here.
Basically, I want my list view to update without having to refresh the page. How to I make the model
used in ngFor
listen to changes?
model
with another component or is the 'list' in the same component definition as your row editor? – Kelwin