6.7.0, Angular, .NET Framework
I want to display certain AppMenuItems only in dependency of certain features.
I couldn't find anything about it in documentation, but I found a 2 years old support question here: [Using featureDependency in Navigation Provider? #1880](https://support.aspnetzero.com/QA/Questions/1880)
The problem is, I don't know where to import SimpleFeatureDependency from.
5 Answer(s)
-
0
If I do it like this (
app-navigation.service.ts):new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", null, null, null, "FeatureName")then browser console shows error messages.
One of the errors says:
ERROR TypeError: "this.featureDependency is not a function". This is because of (app-navigation.service.ts):showMenuItem(menuItem: AppMenuItem): boolean { ... if (menuItem.hasFeatureDependency() && !menuItem.featureDependencySatisfied()) { hideMenuItem = true; } ... }and (app-menu-item.ts):
featureDependencySatisfied(): boolean { if (this.featureDependency) { return this.featureDependency(); } return false; }this.featureDependency()does not exist ... at least, it's not a function but a property of type any.Do i have to pass on some function?
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
It's a C# class.
Sample usage in test case: https://github.com/aspnetboilerplate/aspnetboilerplate/blob/cb0626b58670e123787c7884aafb3758fb6e3ba6/test/Abp.Zero.SampleApp/Authorization/AppAuthorizationProvider.cs
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
I extended
app-navigation-service.tslike follows:... import { FeatureCheckerService } from '@abp/features/feature-checker.service'; ... constructor( private _permissionCheckerService: PermissionCheckerService, private _featureCheckerService: FeatureCheckerService, private _appSessionService: AppSessionService ) { } ... checkFeature(feature: string): boolean { const result = this._featureCheckerService.isEnabled(feature); abp.log.info(`Feature.isEnabled: ${result}`); return result; } ... new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", null, null, null, this.checkFeature("FeatureName"))But result is always
false...EDIT
There was a type in my feature name ... now I'm back at
ERROR TypeError: "this.featureDependency is not a function"since the function is executed (!?) when passed on ... changing it to:new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", null, null, null, (): boolean => { return this.checkFeature("FeatureName"); })leads to:
ERROR TypeError: "_v.parent.context.item.items is null"Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
2
Yes, you can do it like https://github.com/aspnetzero/aspnet-zero-core/issues/1632#issuecomment-428900148
This should be added to documentation and we will add it, sorry for this.
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image) -
0
Thanks a lot @ismcagdas!
Using
new AppMenuItem("MenuItemName", "PermissionName", "fas fa-icon", "/app/main/page", undefined, undefined, undefined, () => { return this._featureCheckerService.isEnabled("FeatureName"); })works : )
Markdown is supportedCopy & paste or drag & drop images (max 30 MB per image)