错误:模块'SharedModule'导入的意外指令'DashboardPage'。请添加@NgModule注释

时间:2017-12-26 16:32:57

标签: angular typescript ionic2 ionic3

我正在尝试在app.module.ts文件中使用DashboardPage作为共享模块,因为我面临的错误如“Error:Unexpected directive'DashboardPage'由模块'SharedModule'导入。请添加@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 {
}

1 个答案:

答案 0 :(得分:2)

您混淆了所有属性:

declarations: [
    PROVIDERS
],
imports: [
    CommonModule,
    DashboardPage,
],
exports: [
    DashboardPage,
]

PROVIDERS应该在... providers中声明(虽然您似乎正在重新声明已在应用模块中声明的那些,这不是一个好主意)。 imports应该包含模块,而不是指令。 DashboardPage是一个指令,因此它应该放在declarations中,而不是放在imports中。