angular - 组件是2个模块声明的一部分

标签 angular build ionic2 declaration ionic3

我尝试构建一个 ionic 2 应用程序。 当我在浏览器中使用 ionic serve 尝试应用程序或在模拟器上启动它时,一切正常。

但是当我每次尝试构建它时都会出错

ionic-app-script tast: "build"
Error Type AddEvent in "PATH"/add.event.ts is part of the declarations of 2 modules: AppModule in "PATH"/app.modules.ts and AddEvent in "PATH"/add-event.module.ts.
Please consider moving AddEvent in "PATH"/add-event.ts to a higher module that imports AppModule in "PATH"/app.module.ts and AddEventModule.
You can also create a new NgModule that exports and includes AddEvent then import that NgModule in AppModule and AddEventModule

我的 AppModule 是

import { NgModule, ErrorHandler } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
import { AngularFireModule } from 'angularfire2';
import { MyApp } from './app.component';
import { Eventdata } from '../providers/eventdata';
import { AuthProvider } from '../providers/auth-provider';
import { HttpModule } from '@angular/http';

import { HomePage } from '../pages/home/home';
import { Login } from '../pages/login/login';
import { Register } from '../pages/register/register';
import { AddEvent } from '../pages/add-event/add-event';
import { EventDetails } from '../pages/event-details/event-details';

import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
   

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    Login,
    Register,
    AddEvent,
    EventDetails
    
  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpModule,
    AngularFireModule.initializeApp(config)
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    Login,
    Register,
    AddEvent,
    EventDetails
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}, Eventdata, AuthProvider
  ]
})
export class AppModule {}

而我的 add-event.module.ts 是

import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { AddEvent } from './add-event';

@NgModule({
  declarations: [
    AddEvent,
  ],
  imports: [
    IonicPageModule.forChild(AddEvent),
  ],
  exports: [
    AddEvent
  ]
})
export class AddEventModule {}

我知道我必须删除其中一个声明,但我不知道如何。

如果我从 AppModule 中删除声明,我会在运行 ionic serve 时收到一个找不到登录页面的错误

最佳答案

AppModule 中删除声明,但更新 AppModule 配置以导入您的 AddEventModule

.....
import { AddEventModule } from './add-event.module';  // <-- don't forget to import the AddEventModule class

@NgModule({
  declarations: [
    MyApp,
    HomePage,
    Login,
    Register,
    //AddEvent,  <--- remove this
    EventDetails

  ],
  imports: [
    BrowserModule,
    IonicModule.forRoot(MyApp),
    HttpModule,
    AngularFireModule.initializeApp(config),
    AddEventModule,  // <--- add this import here
  ],
  bootstrap: [IonicApp],
  entryComponents: [
    MyApp,
    HomePage,
    Login,
    Register,
    AddEvent,
    EventDetails
  ],
  providers: [
    StatusBar,
    SplashScreen,
    {provide: ErrorHandler, useClass: IonicErrorHandler}, Eventdata, AuthProvider
  ]
})
export class AppModule {}

还有,

请注意,如果您想在该模块之外使用 AddEventModule 组件,那么导出 AddEvent 组件非常重要。幸运的是,您已经进行了配置,但如果它被省略,如果您尝试在 AppModule 的另一个组件中使用 AddEvent 组件,则会出现错误/p>

关于angular - 组件是2个模块声明的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43598311/

相关文章:

javascript - 如何在 Angular 中设置动态填充的字符串(插入的字符串)的样式?

android - 如何修复 travis.yml 中被拒绝的 gradlew 权限?

angular - 如何将 Angular 7 升级到 Angular 13

angular - 如何从 Observable 返回数组

c - 如何在构建时计算 'C' 中的平方根?

android ant build 在 ant release 命令上失败

AngularFire2 打字 : "Property ' take' does not exist on type 'FirebaseObjectObservable<any>' "

mysql - Angular 2 待办事项应用程序未在 MySQL 数据库中存储新任务

cordova - ionic API 和 ionic native API 之间的区别

angular - 属性 'contentDocument' 在类型 'HTMLElement' 上不存在