I have below service
@Injectable({
providedIn: 'root'
})
export class LoggedInUserService {
constructor( ) {
console.log('constructor call');
}
}
the constructor is being called when 'acctPage' page directly loaded like doing refresh But when I get navigated by a page like
this.router.navigate(['/acctPage']);
The constructor does not call.
I have created an object in the constructor of acctPage
constructor(private ser serviceName)
I tried creating one project https://stackblitz.com/edit/angular-zje9ww?file=src%2Fapp%2Fapp.module.ts
But since I am new not able to complete this
What I am missing
Well, it does make sense because thats what a constructor does. It's being called only once when the page is being constructed, that's why when you refresh the page it's being called. From now on the router will use the constructed component and won't need to build it again and again every time a router link is clicked.