【发布时间】:2017-05-04 17:35:05
【问题描述】:
我正在使用 Ionic3,并且正在实施延迟加载以提高启动性能。
我已经转换了以下内容:
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 { }
如您所见,我导入了 ControlMessages,这是一个自定义组件(与 app.module.ts 中导入的预加载完美配合)。
但是,当我尝试访问 LoginEmailPage 时,我收到以下运行时错误:
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.
任何建议表示赞赏。
附言ControlMessages 仍被导入到 app.module.ts 以供其他使用它的页面使用。
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;
}
}
【问题讨论】:
-
ControlMessages 是页面还是公共组件?
-
它是
Component。 -
这里有一个类似的问题。但是,建议的解决方案说将导入放在
app.module.ts,这不利于延迟加载。 stackoverflow.com/questions/43603515/… -
没有解决方案说要从 app.module.ts 中删除导入
标签: angular ionic-framework ionic2 ionic3