Skip to content

Navigation Menu

Sign in
Sign up

angular-structural-directive not working as explained in medium article #1033

Unanswered
jatingandhi28 asked this question in Q&A
Discussion options

Hi Team, I didn't find this one functional? do we have to write code in it? or am I missing something?

You must be logged in to vote

Replies: 1 comment 4 replies

Comment options

What do you mean ? Can you explain what it's not working for you ?

You must be logged in to vote
4 replies
Comment options

I have been trying to run this in github codespaces but when I click on Admin or any role it doesn't do anything. It shows same page as we can see in information.component.ts there is nothing mentioned on the div, how will it filter than based on role.

Can't find code as well as mentioned in medium blog -
https://medium.com/@thomas.laforge/create-a-custom-structural-directive-to-manage-permissions-like-a-pro-11a1acad30ad

in 6-structural-directive there is no directive file as mentioned in the above blog. Please help.

Comment options

You can't run a closed PR in GitHub codespaces.

Comment options

Okay. Let me try at local environment. But I could not find the code mentioned in medium blog as well. Could you please help me?

Comment options

@jatingandhi28 The article doesn't explain everything and you have fill in some gaps.

First, you need to cd into the 6-structural-directive folder's app folder and use npx nx g directive hasRole. It will ask you what schematic to use either option should work. I went with nx schematic and the second choice on the second prompt.

The imports don't come up in VS Code when you copy and paste solution 1 into the new directive file.
This is the necessary import:

import {injectDestroyService, provideDestroyService} from "../../../libs/shared/utils/src/lib/destroy-service.service"

Then you need to add the code for isAdmin$ and hasAnyRole from user.store.ts in this PR .

Then you need add the hasRole directives to the template, etc.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet

AltStyle によって変換されたページ (->オリジナル) /