Search code examples
angular7angular7-router

Switch to another angular component on function calling


I am trying to call a component from another component on function calls.

In my Project, I have a total of two components.

pages/component1/

pages/tables/maintables

as mentioned above I have a total of two components defined in Angular 7.

Now in component1 component, I have a function which is I am calling from another function in the maintables component.

below is a code how I am calling a component in function.

this.router.navigateByUrl('/component1');

but the above line is not working properly.it is not redirected to the component1 component.

can anyone help me in this how to call another angular component from a different component?

Thanks in Advance!


Solution

  • all the problem is resolved now, I import the component in both app.routing.module + another module which is the parent module of my all components.

    So it resolves my issues.

    Thank you so much to all for your help.