[英]Error: Unexpected directive 'DashboardPage' imported by the module 'SharedModule'. Please add a @NgModule annotation
I am trying to use DashboardPage in app.module.ts file as shared module, In that I am facing error like "Error: Unexpected directive 'DashboardPage' imported by the module 'SharedModule'. Please add a @NgModule annotation." 我试图将app.module.ts文件中的DashboardPage用作共享模块,因为我遇到了诸如“错误:模块'SharedModule'导入的意外指令'DashboardPage'。请添加@NgModule批注。”
Give some suggestions to resolve this issue. 提供一些建议来解决此问题。 Thanks in advance.
提前致谢。
Below the codes, 在代码下方,
app.module.ts 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 file 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 {
}
You mixed up all the attributes: 您混合了所有属性:
declarations: [
PROVIDERS
],
imports: [
CommonModule,
DashboardPage,
],
exports: [
DashboardPage,
]
PROVIDERS
should be declared in... providers
(although it seems you're redeclaring those that are already declared in the app module, which is not a good idea). 应在...
providers
声明PROVIDERS
(尽管您似乎在重新声明已在app模块中声明的那些,但这不是一个好主意)。 imports
is supposed to contain modules, not directives. imports
应该包含模块,而不是指令。 DashboardPage
is a directive, so it should go in declarations
, not in imports
. DashboardPage
是指令,因此它应放在declarations
,而不要在imports
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.