I have two components (not parent-child). First component has search input field that should be populated on a button click, with a value that is available in second component. Button click also happens in second component. I tried Input Output, but it seems this is only for parent-child connection. I also tried to save the value I need in a service, and then fetch it in the first component through that service, but I get undefined. Appreciate help.
Here is my code:
FIRST COMPONENT
<mat-form-field>
<mat-label class="mat-uppercase has-events">
<span> {{ "SEARCH_DEVICES" | translate | uppercase }}</span>
</mat-label>
<input type="text" formControlName="actorDevice" matInput />
</mat-form-field>
SECOND COMPONENT
TS
passDevice(id: string) {
this.deviceService.getDeviceById(id).subscribe((res) => {
this.deviceName = res.deviceName[0].name;
});
this.deviceService.selectedDeviceName = this.deviceName;
}
HTML
<ng-container matColumnDef="selectRow">
<mat-header-cell *matHeaderCellDef>
{{ "SELECT" | translate }}
</mat-header-cell>
<mat-cell *matCellDef="let row">
<button mat-button type="button" (click)="passDevice(row.id)">
Select
</button>
</mat-cell>
</ng-container>