Base solution for your next web application
Open Closed

How to access LoginService from topbar? #8279


User avatar
0
timmackey created

I tried injecting the LoginService into 'topbar.component.ts' in the constructor thusly: private _loginService: LoginService,, (and imported it) import { LoginService } from '@account/login/login.service';

However, after logging in, I get a continuous stream of errors on the console:

null: ERROR
null: NullInjectorError: StaticInjectorError(RootModule)[TopBarComponent -> LoginService]:
no debug adapter:
null: ERROR CONTEXT
null: DebugContext_ {view: Object, nodeIndex: 31, nodeDef: Object, elDef: Object, elView: Object}
...

I am returning a custom boolean in the 'authenticationResult' that I want to use in topbar.


2 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team

    LoginService exists in AccountModule and TopBarComponent is in AppModule.

    You can consider putting this custom boolean into AppSessionService.

  • User Avatar
    0
    timmackey created

    @maliming - Thank you for pointing out AppSessionService.

    The boolean I wanted on the client was a custom property in User. The simple solution was to add the property (named the same) in UserLoginInfoDto (defined on the server). On the client I added argument private _appSessionService: AppSessionService in the constructor, then picked up this._appSessionService.user.MyCustomBoolean in ngOnInit().