'Angular Ngoninit getting called everytime while routing

I have one component Details where the routes for other child components is there. What is happening is that when I route to any other child component then the onint of the Details is getting called.

For Example- example.com/details/123123123/profile is my current route

I am navigating to example.com/details/12312331/pastappointment

then the NgOnInit of Details is getting called. Which is calling all the apis that I don't want.



Solution 1:[1]

You have to use

<router-outlet></router-outlet> 

inside your Details component.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Arthur PĂ©rez