简体   繁体   English

由模块'AppModule'导入的意外指令'LoginPage'。 请添加@NgModule注释

[英]Unexpected directive 'LoginPage' imported by the module 'AppModule'. Please add a @NgModule annotation

I am developing an application using ionic 2. The main features of the application is login screen and then appear a dash board with side menu. 我正在使用离子2开发一个应用程序。该应用程序的主要功能是登录屏幕,然后出现一个带侧边菜单的仪表板。 Side menu will not be in login screen. 侧边菜单不在登录屏幕中。 I did it. 我做的。 but do not know the following error is coming out again and again. 但不知道以下错误会一次又一次地出现。

The error is 错误是

Unexpected directive 'LoginPage' imported by the module 'AppModule'. 由模块'AppModule'导入的意外指令'LoginPage'。 Please add a @NgModule annotation. 请添加@NgModule注释。

Here I'm giving my code.. 我在这里给我的代码..

app.module.ts app.module.ts

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';    
import { ErrorHandler } from '@angular/core';    
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';    
import { MyApp } from './app.component';    
import { HomePage } from '../pages/home/home';    
import { ListPage } from '../pages/list/list';    
import { LoginPage } from "./login/login";    
import { MenuComponent } from "./menu.component";    
@NgModule({    
  declarations: [  
    MyApp,    
    HomePage,   
    ListPage,    
    MenuComponent    
  ],

  imports: [    
    BrowserModule,    
    IonicModule.forRoot(MyApp),   
    LoginPage   
  ],

  bootstrap: [IonicApp],

  entryComponents: [ 
    MyApp,    
    HomePage,   
    ListPage,
    MenuComponent
  ],
  providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }]
})

export class AppModule {}


App.component.ts

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';  
import { LoginService } from "./login/login.service";
import { LoginPage } from "./login/login"; 
import { MenuComponent } from "./menu.component";

@Component({
   template: '<ion-nav #baseNav></ion-nav>',
})
export class MyApp {

  @ViewChild('baseNav') nav: Nav;

  constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private loginService: LoginService) {
    this.initializeApp();
 }

 ngOnInit() {
    const componentStack: Array<{page: Component}> = [{
      page: MenuComponent
    }];
    if (!this.loginService.isLoggedIn) {

      componentStack.push({ page: LoginPage });
    }

    this.nav.insertPages(0, componentStack, { animate: false });
  }


  initializeApp() {
    this.platform.ready().then(() => {
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });
  }
}

How may I resolve this issue...? 我该如何解决这个问题......? I'm using Angular 4. 我正在使用Angular 4。

@NgModule({

  declarations: [
    MyApp,    
    HomePage,    
    ListPage,    
    MenuComponent,
    LoginPage      // loginPgae will be here not in imports  
  ],    
  imports: [   
    BrowserModule,    
    IonicModule.forRoot(MyApp)        
  ],    
  bootstrap: [IonicApp],    
  entryComponents: [    
    MyApp,    
    HomePage,    
    ListPage,    
    MenuComponent    
  ],
  providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }]    
})

In your code, You have written "LoginPage" in Imports in @ngModule. 在您的代码中,您在@ngModule中的Imports中编写了“LoginPage”。 Instead, write it in the declaration and in EntryComponents. 相反,将它写在声明和EntryComponents中。

 @NgModule({ declarations: [ MyApp, HomePage, ListPage, MenuComponent, LoginPage //add LoginPage here ], imports: [ BrowserModule, IonicModule.forRoot(MyApp), ], bootstrap: [IonicApp], entryComponents: [ MyApp, HomePage, ListPage, MenuComponent, LoginPage //add LoginPage here ], providers: [{ provide: ErrorHandler, useClass: IonicErrorHandler }] }) 

You have to Declare your components in Declaration. 您必须在声明中声明您的组件。

The way you import components into a module is you add them to the declarations. 将组件导入模块的方法是将它们添加到声明中。 This is true for in general for all component imports. 对于所有组件导入,通常都是如此。

declarations: [ Component1, Component2, ... ], 声明:[Component1,Component2,...],

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 由模块&#39;AppModule&#39;导入的意外指令&#39;MatSpinner&#39;。 请添加@NgModule注释 - Unexpected directive 'MatSpinner' 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 模块&#39;AppModule&#39;导入的意外值&#39;MDCTextField&#39;。 请添加@NgModule注释 - Unexpected value 'MDCTextField' imported by the module 'AppModule'. Please add a @NgModule annotation 模块'AppModule'导入的意外值'DataTablesModule'。请添加@NgModule注释 - Unexpected value 'DataTablesModule' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“AppModule”导入的意外值“MatSnackBar”。 请添加@NgModule 注解 - Unexpected value 'MatSnackBar' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“AppModule”导入的意外值“FusionChartsModule”。 请添加@NgModule 注解 - Unexpected value 'FusionChartsModule' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“ AppModule”导入的异常值“ AngularFireDatabase”。 请添加@NgModule批注 - Unexpected value 'AngularFireDatabase' imported by the module 'AppModule'. Please add a @NgModule annotation 模块“ AppModule”导入了意外值“ Validators”。 请添加@NgModule批注 - Unexpected value 'Validators' imported by the module 'AppModule'. Please add a @NgModule annotation 由模块“AppModule”导入的意外值“FormBuilder”。 请添加@NgModule 注释 - Unexpected value 'FormBuilder' imported by the module 'AppModule'. Please add a @NgModule annotation
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM