简体   繁体   English

错误:模块“ SharedModule”导入了意外的指令“ DashboardPage”。 请添加@NgModule批注

[英]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.

相关问题 未捕获的错误:模块'AppModule'导入了意外的值'SharedModule'。 请添加@NgModule批注 - Uncaught Error: Unexpected value 'SharedModule' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块'AppModule'导入的意外指令'LoginComponent'。请添加@NgModule注释 - Unexpected directive 'LoginComponent' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“AppModule”导入的意外指令“MatAutoCompleteTrigger”。 请添加@NgModule 注释 - Unexpected directive 'MatAutoCompleteTrigger' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块'AppModule'导入的意外指令'LoginPage'。 请添加@NgModule注释 - Unexpected directive 'LoginPage' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块'AppModule'导入的意外指令'MatSpinner'。 请添加@NgModule注释 - Unexpected directive 'MatSpinner' imported by the module 'AppModule'. Please add a @NgModule annotation 模块导入的意外指令请添加@ngmodule注释 - unexpected directive imported by the module please add a @ngmodule annotation 模块“DynamicTestModule”导入的意外指令“InformationComponent”。 请添加@NgModule 注解 - Unexpected directive 'InformationComponent' imported by the module 'DynamicTestModule'. Please add a @NgModule annotation 未捕获的错误:模块“MyMaterialModule”导入的意外指令“angular-material”。 请添加@NgModule 注释。 角 5 - Uncaught Error: Unexpected directive 'angular-material' imported by the module 'MyMaterialModule'. Please add a @NgModule annotation. angular 5 未捕获的错误:模块'AppModule'导入了意外的指令'ProductsComponent'。 请添加@NgModule批注 - Uncaught Error: Unexpected directive 'ProductsComponent' imported by the module 'AppModule'. Please add a @NgModule annotation 未捕获的错误:由模块“AppModule”导入的意外指令“NavComponent”。 请添加@NgModule 注释 - Uncaught Error: Unexpected directive 'NavComponent' imported by the module 'AppModule'. Please add a @NgModule annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM