1

I am trying jhipster 6 with a demo app using the defaults. Just tried to remove the element <jhi-page-ribbon></jhi-page-ribbon> from 'src/main/webapp/app/layouts/main/main.component.html'. This removes the page-ribbon from the UI, but the navigation breaks as the accountService is not injected to the loginService. I understand that we can remove the ribbon by configuring the spring profiles. But I don't understand why removing the ribbon component from UI, breaks the accountService injection in to the loginService. Can anyone explain?

Looking at the debug console on chrome/firefox, I see accountService is undefined in loginService when I remove the jhi-page-ribbon. if I put it back, it is injected properly and works fine.

Steps:

install jhipster 6. under a new demo folder, run jhipster choosing defaults.

run ./mvnw from one terminal and run npm start from another terminal

from the source file 'src/main/webapp/app/layouts/main/main.component.html', remove the component <jhi-page-ribbon></jhi-page-ribbon>. Now try to login as user or admin. It will allow to login, but the navigation breaks.

Expected:

Removing the <jhi-page-ribbon></jhi-page-ribbon> should not break injection of the accountService into the loginService and should not break the navigation.

onsjkm
  • 31
  • 2
  • the ribbon will go away if you run with the `prod` profile, which is a very good practice – Alejandro May 07 '19 at 23:12
  • 1
    Thanks @alejandro, but the question is not really about removing the ribbon. But why removing the ribbon component breaks the injection. – onsjkm May 07 '19 at 23:26
  • 1
    I had the same problem. [It solved](https://stackoverflow.com/questions/55230263/angular-7-injected-service-is-undefined) solved my problem – new java dev May 08 '19 at 05:55
  • Thanks @javadev. I looked into it as well. It solves the login problem, but still breaks the logout navigation. Also it seems like a work around not a real solution. I would like to understand the injection issue here. Another interesting thing is loginService has two dependencies injected accountService and authServerProvider. While authServerProvider is injected properly, its the accountService thats undefined. Both are defined in the core module and injected to root. Wonder whats the difference? – onsjkm May 08 '19 at 15:53

1 Answers1

1

Here is what I found: AccountService depends on JhiLanguageService, which is not marked as injectable. So I injected it to core module and it worked fine. Still not sure what's is the best place to inject this dependency.

export class AppCoreModule {
  constructor(private languageService: JhiLanguageService) {
    registerLocaleData(locale);
  }
}
onsjkm
  • 31
  • 2