I have a form where the user enters some data, then sends a POST. Now I am working on a feature to allow editing of previously entered information. Some of the inputs in the fields have nested objects, as:
export class Transfer {
constructor(
public id: number,
public destination: string,
public market: string,
public project: Project,
public workstream: Workstream,
public contact: Contact
)
}
export class Workstream {
constructor(
public id: number,
public workStream: string
) { }
}
export class Contact {
constructor(
public id: number,
public name: string
) { }
}
When loading the information to the form, fields containing strings or numbers work well, but objects don't show the correct information. The field for Contact gives me a [object Object], while Workstream does not preselect the right option from a drop down.
<!-- Workstream -->
<mat-form-field class="example-full-width">
<mat-label>Workstream</mat-label>
<mat-select [(ngModel)]="transfer.workstream" name="workstream" [(value)]="transfer.workstream">
<mat-option *ngFor="let workstream of workstreams$ | async" [value]="workstream">
{{workstream.workStream}}
</mat-option>
</mat-select>
</mat-form-field>
<!-- Contact -->
<mat-form-field class="example-full-width">
<input matInput placeholder="Contact" [(ngModel)]="transfer.contact" name="contact" value="transfer.contact.name"
#contactSearchBox (input)="searchContact(contactSearchBox.value)" [matAutocomplete]="auto">
</mat-form-field>
<mat-autocomplete #auto="matAutocomplete">
<mat-option *ngFor="let contact of contacts$ | async" [value]="contact.name"
(click)="selectContact(contact)">
{{contact.name}}
</mat-option>
</mat-autocomplete>
In the contact field the user is able to search by name, which works. Any clues on how to implement this? Thanks!