Hello everyone!
I'm seeking assistance. In my Angular 10 application, I have a component called A.
Within this component, there is a <router-outlet>
and routes defined in the routes.ts file.
My goal is to modify a variable (field) inside component A by clicking a button from another component named B, which is a route within the <router-outlet>
. How can I achieve this?
Let's consider the following scenario:
A.component.html
<B [changeFieldOfA]="func"></B>
A.component.ts
export class A {
foo: string = "";
func() {
this.foo = "bar";
}
}
By passing a function that updates the field in component A to component B, everything works as intended.
However, how can we handle a situation like this?:
A.component.html
<router-outlet></router-outlet>
routes.ts
{path: "b", component: B}
In this case, I aim to invoke the func(), which belongs to A and modifies its field, within B. Unfortunately, using Input() is no longer feasible due to the routing constraints. Is there an alternative approach?