作为根角的素数5

问题描述 投票:0回答:1
  • 我正在使用angular5中的项目,其中我有不同的模块用于不同的实体。
  • 我需要使用primeng作为组件ui,我正确安装它,使用单个app模块测试demo angular项目:

我有以下模块:

app(生成角度,app.module.ts)

用户(user.module.ts)

1. create user component

2  update user component

管理员(admin.module.ts)

1. create admin component

2 . update user component

问题:当我使用多个模块时,如何在app.module.ts文件中设置primeng?

我正在使用createuser.component中的primeng按钮

> <button pButton type="button" label="Click" ></button> <p-button
> label="Click" ></p-button>

我得到了以下错误

'p-button'不是已知元素:1。如果'p-button'是Angular组件,则验证它是否是该模块的一部分。 2.如果'p-button'是Web组件,则将'CUSTOM_ELEMENTS_SCHEMA'添加到此组件的'@ NgModule.schemas'以禁止显示此消息。 (“[ERROR - >]”):ng:///PreMeritModule/AddformComponent.html@1:0

我的app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';

//prime ng needs following modules with browser animation module and froms module

import { PanelModule } from 'primeng/components/panel/panel';
import { ButtonModule } from 'primeng/components/button/button';



import { AppComponent } from './app.component';
import { userModule } from './user/user.module';
import { adminModule } from './admin/admin.module';

// Routing Module
import { AppRoutingModule } from './app.routing';


@NgModule({
  imports: [
      userModule,
      adminModule
    BrowserModule,
    FormsModule,
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,

    PanelModule,
    ButtonModule
  ],
  declarations: [
    AppComponent,

  ],
  providers: [{
    provide: LocationStrategy,
    useClass: HashLocationStrategy
  }],
  bootstrap: [AppComponent]
})
export class AppModule { }
angular5 primeng
1个回答
0
投票

修改此导入:

import { NgModule } from '@angular/core';

...加上...

import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';

...然后:

@NgModule({
  imports: ...
  ...
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})

在全:

import { BrowserModule } from '@angular/platform-browser';
import { CUSTOM_ELEMENTS_SCHEMA, NgModule } from '@angular/core';
import { LocationStrategy, HashLocationStrategy } from '@angular/common';

//prime ng needs following modules with browser animation module and froms module

import { PanelModule } from 'primeng/components/panel/panel';
import { ButtonModule } from 'primeng/components/button/button';



import { AppComponent } from './app.component';
import { userModule } from './user/user.module';
import { adminModule } from './admin/admin.module';

// Routing Module
import { AppRoutingModule } from './app.routing';


@NgModule({
  imports: [
      userModule,
      adminModule
    BrowserModule,
    FormsModule,
    BrowserModule,
    AppRoutingModule,
    BrowserAnimationsModule,

    PanelModule,
    ButtonModule
  ],
  declarations: [
    AppComponent,

  ],
  providers: [{
    provide: LocationStrategy,
    useClass: HashLocationStrategy
  }],
  bootstrap: [AppComponent],
  schemas: [CUSTOM_ELEMENTS_SCHEMA]
})
export class AppModule { }
© www.soinside.com 2019 - 2024. All rights reserved.