Join the Stack Overflow Community
Stack Overflow is a community of 6.5 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up

I am using mgechev's angular2 seed for my project. I am working on Angular2 for last 6 months (following the world with all the RCs to Final release). I am stuck with a requirement my client has. I wish you guys could help.

Here is the problem. Base on user role:

ROLE_ADMIN

ROLE_REVIEWER

Web app should be able to load specific modules and display. Say,

  • if user role is ROLE_ADMIN then load angular2 modules Module1 & Module2
  • if user role is ROLE_REVIEWER then load angular2 modules Module1 only.

When I say load, it means it must fetch the module files (everything that is bundled with the module) from the server, inject into Angular2 app and display that module.

So, if the user role is ROLE_REVIEWER I shall be able to see only Module1 that means Module2 should not be even fetched from the server.

EDIT Here is difficult part, url is not changed while doing it. Consider this module as widgets which loads on your dashboard /dashboard. Thus no url change is expected while loading these modules.

Hope my question is explanatory enough. Please suggestion what all I should do or research or study to achieve this.

My best guess, I have to do the following:

  • Conditional lazy loading (without routing) & then,
  • Dynamic Loading

But I do not know how.

share|improve this question
    
Have you managed to find the answer to this issue? I am having the same problem. – IvanSt Nov 4 at 8:29
    
I know now how it will works now, but I couldn't prototype it successfully. – Savaratkar Nov 5 at 5:25
    
I used this link from where I got the idea: github.com/mgechev/angular-seed/issues/1358 – Savaratkar Nov 5 at 5:26
    

You need to use routing and lazy loading. The strategy I use is to configure dynamically the Router based on the role. I hope this helps

AFTER READING YOUR EDIT

After reading your edit, my understanding is that with the word 'module' you identify a series of widgets that are displyed or not depending on the role. In such case you do not need routing and lazy loading. It is just some conditional logic that you can code in the template of you 'dashboard' Component using *ngIf.

I suggest though not to use the word 'module' in this sense. Module is either used in the EC6 sense or in the Angular2 sense. In the first case it is related to the 'import'/'export' concept. In the second case it is related to lazy loading and routing.

I hope this helps

share|improve this answer
    
hi @Picci url is not changed while loading these modules. I have modified my question. Please have a look. – Savaratkar Oct 17 at 6:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.