Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Multiple Modules #7

Open
AlisonVilela opened this issue Oct 27, 2017 · 8 comments
Open

Multiple Modules #7

AlisonVilela opened this issue Oct 27, 2017 · 8 comments

Comments

@AlisonVilela
Copy link

I have a problem when I use [hasPermission]="role" in sub-modules, I imported Ng2Permission in my app.module and if I import into another.module for use that, is created another instance for PermissionService and all business rules about permissions will been lost.

@JavadRasouli do you have any suggestion?

@AlexandreKavalerski
Copy link

@AlisonVilela take a look about CoreModules here: ngModule. I think it could solve your problem

@AlisonVilela
Copy link
Author

Yeah @AlexandreKavalerski , I have a core.module but when I import Ng2Permission and PermissionService don't work in SubModules Routes

For example.:

  • core.module Import Ng2Permission and PermissionService
  • app.module Import core.module
  • app.routing.module Use PermissionGuard
  • admin Directory
    • admin.module Import core.module
    • admin.routing.module Use PermissionGuard

In start the app, I define the roles this.permissionService.define(this.roles)
PermissionService.store in add.routing.module OK
PermissionService.store in admin.routing.module always empty

When I import Ng2Permission in app.module always routes works fine, including admin.routing.module but the directive[hasPermission] don't work in all pages of admin.module

So, when I import Ng2Permission in core.module or in admin.module, routing roles with PermissionGuard stops working because PermissionService.store is empty in this SubModule

I thing PermissionService has been created another instance when import Ng2Permission in another module

@JavadRasouli
Copy link
Owner

PermissionService is singletone and there is just one instance available in all modules. i must test your scenario at another time.

@JavadRasouli
Copy link
Owner

Only the root AppModule should import the CoreModule or Ng2Permission. In your code core.module multiple import. Once in app.module and again in admin.module. This will make several instances of the PermissionService.

@AlisonVilela
Copy link
Author

AlisonVilela commented Nov 13, 2017

@JavadRasouli Ok, but I need to import Ng2Permission into CoreModule and I need to import CoreModule into multiple modules

@jmparraguez-haulmer
Copy link

@AlisonVilela
Copy link
Author

@jmparra very interesting, @JavadRasouli if we configure forRoot in this way? we could then import into other modules without duplicating the service

@nhthuan
Copy link

nhthuan commented May 3, 2018

Hi all,
I have same issue with lazy load modules also.
I see that @JavadRasouli already update ng2-permission.module.ts to add forRoot method in git repo, but yarn or npm still fetchs the old angular2-permission-0.1.3.tgz package which doesn't contain implementation forRoot method (it's same even I get the link and paste to browser).
The link I tried:
https://registry.yarnpkg.com/angular2-permission/-/angular2-permission-0.1.3.tgz

I already try to clear yarn cache by yarn cache clean angular2-permission but without good result
Could you please tell me how can I use the latest implementation for angular2-permission?
Thanks in advanced,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants