指令 *ngxPermissionsOnly

问题描述 投票:0回答:3

我对库 ngx-permissions 的指令有疑问。 这些是我的角度依赖项的版本:

    "@angular/animations": "^5.0.3",
    "@angular/common": "^5.0.3",
    "@angular/compiler": "^5.0.3",
    "@angular/core": "^5.0.3",
    "@angular/forms": "^5.0.3",
    "@angular/http": "^5.0.3",
    "@angular/platform-browser": "^5.0.3",
    "@angular/platform-browser-dynamic": "^5.0.3",
    "@angular/router": "^5.0.3",

我正在关注这个例子

我使用的模块版本:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

import { NgxPermissionsModule } from 'ngx-permissions';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,

    // Specify your library as an import
     NgxPermissionsModule.forRoot()
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

我可以毫无问题地使用服务,但仅在指令方面出现错误。 错误如下:

Can't bind to 'ngxPermissionsOnly' since it isn't a known property of 'div'. ("
    </div>
            </div>
                <div [ERROR ->]*ngxPermissionsOnly="['ADMIN', 'GUEST']" class="m-portlet__head-tools">
                    <ul class="nav nav-pil"): ng:///DashboardModule/DashboardComponent.html@35:10
Property binding ngxPermissionsOnly not used by any directive on an embedded template. Make sure that the property name is spelled correctly and all directives are listed in the "@NgModule.declarations". ("
                    </div>
                </div>
                [ERROR ->]<div *ngxPermissionsOnly="['ADMIN', 'GUEST']" class="m-portlet__head-tools">
                    <ul class="nav na"): ng:///DashboardModule/DashboardComponent.html@35:5
angular5
3个回答
7
投票

我遇到了同样的问题,我的解决方法是为子模块添加 NgxPermissionsModule

NgxPermissionsModule.forChild()

1
投票

我想说我也面临着同样的问题。但就我而言;我有一个共享模块,我按照维基所说的做了同样的事情,但解决方案只是导出 NgxPermissionsModule。

我的问题解决了,代码工作正常。检查您是否有相同的情况,我的修复是否适合您。

谢谢


0
投票

我的问题是我在旧的 Angular 版本上使用最新版本的 NgxPermissionModule。确保

© www.soinside.com 2019 - 2024. All rights reserved.