I am using Ionic3, and am in the process of implementing Lazy Loading in order to improve startup performance.
I have converted the following:
loginemail.module.ts
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { LoginEmailPage } from './loginemail';
import { ControlMessages } from '../validation/controlMessages';
@NgModule({
declarations: [LoginEmailPage],
imports: [IonicPageModule.forChild(LoginEmailPage), ControlMessages],
})
export class LoginEmailPageModule { }
As you can see, I import ControlMessages, which is a custom component (that worked perfectly with eager loading imported in app.module.ts).
However, when I try access the LoginEmailPage, I get the following runtime error:
core.es5.js:1085 ERROR Error: Uncaught (in promise): Error: Unexpected directive 'ControlMessages' imported by the module 'LoginEmailPageModule'. Please add a @NgModule annotation.
Error: Unexpected directive 'ControlMessages' imported by the module 'LoginEmailPageModule'. Please add a @NgModule annotation.
Any advise appreciated.
p.s. ControlMessages is still imported in app.module.ts for other pages that use it.
controlMessages.ts
import { Component, Input } from '@angular/core';
import { FormControl } from '@angular/forms';
import { ValidationService } from './validationService';
@Component({
selector: 'control-messages',
template: `<div *ngIf="errorMessage !== null">{{errorMessage}}</div>`
})
export class ControlMessages {
@Input() control: FormControl;
constructor() {
}
get errorMessage(): string {
for (let propertyName in this.control.errors) {
if (this.control.errors.hasOwnProperty(propertyName) && this.control.touched) {
return ValidationService.getValidatorErrorMessage(propertyName, this.control.errors[propertyName]);
}
}
return null;
}
}
Component.app.module.ts, which is not conducive to lazy loading. stackoverflow.com/questions/43603515/…