我试图在app.module.ts文件中使用DashboardPage作为共享模块,因为我遇到错误,如“错误:由模块'SharedModule'导入的错误指令'DashboardPage'。请添加@NgModule注释。”
提出一些解决此问题的建议。提前致谢。
在代码下面,
app.module.ts
import {NgModule, ErrorHandler} from '@angular/core';
import {BrowserModule} from '@angular/platform-browser';
import {HttpModule} from '@angular/http';
import {IonicApp, IonicModule, IonicErrorHandler, IonicPageModule} from 'ionic-angular';
import {MyApp} from './app.component';
import {DatePickerModule} from 'datepicker-ionic2';
import {IonicStorageModule} from '@ionic/storage';
import {PreloadImageModule} from '../components/preload-image/preload-image.module';
import {ShowHidePasswordModule} from "../components/show-hide-password/show-hide-password.module";
import {Login} from '../pages/login/login';
import {DashboardPage} from '../pages/dashboard/dashboard';
import {SharedModule} from '../app/shared/shared-module';
import {PROVIDERS} from '../app/shared/dashboard';
@NgModule({
declarations: [
MyApp,
Login,
],
imports: [
BrowserModule,
HttpModule,
IonicModule.forRoot(MyApp, {
platforms: {
ios: {
autoFocusAssist: 'instant'
}
}
}),
IonicStorageModule.forRoot(),
DatePickerModule,
SharedModule,
IonicPageModule.forChild(Login), PreloadImageModule, ShowHidePasswordModule,
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
Login,
],
providers: [
PROVIDERS,
{provide: ErrorHandler, useClass: IonicErrorHandler},
]
})
export class AppModule {
}
shared-module.ts文件
import {NgModule} from '@angular/core';
import {CommonModule} from "@angular/common";
import {PROVIDERS} from "../shared/dashboard";
import {DashboardPage} from "../../pages/dashboard/dashboard";
@NgModule({
declarations: [
PROVIDERS
],
imports: [
CommonModule,
DashboardPage,
],
exports: [
DashboardPage,
]
})
export class SharedModule {
}
你搞砸了所有的属性:
declarations: [
PROVIDERS
],
imports: [
CommonModule,
DashboardPage,
],
exports: [
DashboardPage,
]
PROVIDERS
应该在...... providers
中声明(虽然看起来你正在重新声明已经在app模块中声明的那些,这不是一个好主意)。 imports
应该包含模块,而不是指令。 DashboardPage
是一个指令,所以它应该在declarations
,而不是在imports
。