Good, I have a parent component with a list, when selecting the selected element is passed to the child component (a form) defined with the decorator @ input .
The problem When I modify some property in the form, it replicates the change in the list
I hope That the change is replicated by a pressed submit
The code
father.html
<div class="container">
<h2>Project List</h2>
<button (click)="expandForm(true)" class="btn btn-default">New</button>
<table class="table table-striped">
<thead>
<tr>
<th>Name</th>
<th>Description</th>
<th>State</th>
</tr>
</thead>
<tbody>
<tr *ngFor="let project of projects" (click)="onSelect(project)">
<td>{{project.name}}</td>
<td>{{project.description}}</td>
<td>{{project.state.description}}</td>
</tr>
</tbody>
</table>
<!--</div>-->
</div>
<project-form [project]="selectedProject">
Child component
export class FormComponent implements OnInit {
@Input()
project: Project;
constructor(private service: PService) { }
ngOnInit() {
}
}
hijo.html
<form (ngSubmit)="onSubmit()" #projectForm="ngForm" *ngIf="_project != null">
<div class="form-group">
<label for="txtName">Name</label>
<input [(ngModel)]="project.name" type="text" class="form-control" id="txtName" name="Name"/>
</div>
<div class="form-group">
<label for="txtDescription">Description</label>
<input [(ngModel)]="_project.description" type="text" class="form-control" id="txtDescription" name="Description"/>
</div>
<div class="form-group">
<label for="ddlState">State</label>
<select [(ngModel)]="project.state" class="form-control" id="ddlState" name="State">
<option *ngFor="let s of projectStates" [ngValue]="s">{{s.description}}</option>
</select>
</div>
<button type="submit" class="btn btn-success">Submit</button>
<button type="reset" (click)="clear()" class="btn btn-default">Cancel</button>
</form>