我已多次尝试在非延迟加载页面中延迟加载组件,但这给了我一个错误
// app.module.ts
import {LoginPage} from '../pages/login/login';
@NgModule({
declarations: [
MyApp,
LoginPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpClientModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
LoginPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
]
})
// login.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { LoginPage } from './login';
import {LoginFormComponent} from '../../components/login-form/login-form';
@NgModule({
declarations: [
LoginPage,
LoginFormComponent
],
imports: [
IonicPageModule.forChild(LoginPage),
],
})
export class LoginPageModule {}
这给我一个错误
please add a @pipe/@directive/@component annotation.
如果可能的话,如何在非延迟加载页面中创建延迟加载组件?
答案 0 :(得分:0)
在Angular中,组件只能在一个模块中注册。
从LoginPage
,declarations[]
移除entryComponents[]
,然后从app.module.ts
@NgModule({
declarations: [
MyApp
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
HttpClientModule
],
bootstrap: [IonicApp],
entryComponents: [
MyApp
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler},
]
})