Quiero actualizar el campo haciendo clic en enviar desde matdialog.
html
<h2>network <mat-icon (click)="openDialog(mytemplate)">add_circle_outline</mat-icon></h2> <ng-template #mytemplate> <div class="container"> <div class="box"> <mat-form-field appearance="outline"> <input matInput placeholder="enter the items" /> </mat-form-field> <button mat-stroked-button mat-dialog-close color="accent">CANCEL</button> <button mat-flat-button color="accent" (click)="onclick()">Submit</button> </div> </div> </ng-template>.ts
provider = []; providers: provider; getnetwork() { this.service.getAllNetworkProviders().subscribe(res => { this.provider = res.data; this.dataSource = this.provider; }); } openDialog(template): void { // ask user to confirm, if he really wants to proceed this.dialogRef = this.dialog.open(template); this.dialogRef.afterClosed().subscribe(isTrue => { if (isTrue) { const activatenetworkprovider = { networkName: this.providers.id }; this.service.networkProviderStatus(activatenetworkprovider).subscribe(data => { this.getnetwork(); this.snackBar.open('Successfully created new network provider sim', 'Close', { duration: 2000 }); }); } }); }modelo.ts
export interface provider { id: number; name: string; }Recibo el error [ERROR TypeError: no se pueden leer las propiedades de undefined (leyendo 'id')].
He actualizado las preguntas.
Esta es una declaración:
providers: provider; No es un objeto/instancia real, sino simplemente un identificador de un objeto. Aún necesita asignar algo a esto con = . Preferiblemente un objeto que contenga una id de miembro (por ejemplo: {id: 1, ... }).
También es una convención nombrar las interfaces con letras mayúsculas, así:
export interface Provider { id: number; name: string; }