I am currently in the process of restructuring my project, focusing on establishing communication between unrelated components while also waiting for a return value from a function call.
Imagine having component1 with function1() and component2 with function2(), both connected through the component.service.
Here is an example of component1:
import { Component, OnInit } from '@angular/core';
import { ComponentService } from '../component.service';
@Component({
selector: 'component1',
template: ''
})
export class Component1 implements OnInit {
constructor() {}
ngOnInit() {
}
function1() {
//do something
let parameter: any = "some Parameter";
let returnValue = function2(parameter);
//do something else
}
}
And component2:
import { Component, OnInit } from '@angular/core';
import { ComponentService } from '../component.service';
@Component({
selector: 'component2',
template: ''
})
export class Component2 implements OnInit {
constructor() {}
ngOnInit() {
}
function2(parameter: string) {
//do something
return parameter + "did something with it";
}
}
Lastly, the componentService:
import { Injectable } from '@angular/core';
@Injectable({
providedIn: 'root'
})
export class ComponentService{
constructor() { }
//???
}
I'm looking for guidance on how to structure the service so that function1() can effectively utilize the returned value from function2(). Any advice on the appropriate setup would be greatly appreciated. Thank you!