2017-04-06 41 views
16

我使用的离子CLI使用此命令生成的页面住宅“forChild”上类型不存在“的typeof IonicModule”

ionic generate page login 
ionic g page login 

然后我得到在浏览器这个错误

Typescript Error 
Property 'forChild' does not exist on type 'typeof IonicModule'. 
E:/workspace/Ionic/myApp/src/pages/login/login.module.ts 
imports: [ 
    IonicModule.forChild(Login), 
], 

也在登录文件夹中创建4个项目。

1.login.html 
2.login.ts 
3.login.module.ts 
4.login.scss 

任何机构都可以解决这个问题。 这里是login.module.ts

import { NgModule } from '@angular/core'; 
import { IonicModule } from 'ionic-angular'; 
import { Login } from './login'; 

@NgModule({ 
    declarations: [ 
    Login, 
    ], 
    imports: [ 
    IonicModule.forChild(Login), 
    ], 
    exports: [ 
    Login 
    ] 
}) 
export class LoginModule {} 

如果我删除此行,应用程序工作正常。

IonicModule.forChild(Login), 

回答

14

IonicModule.forRoot(MyApp)

Github链接here

export class IonicModule { 

/** 
* Set the root app component for you IonicModule 
* @param {any} appRoot The root AppComponent for this app. 
* @param {any} config Config Options for the app. Accepts any config property. 
* @param {any} deepLinkConfig Any configuration needed for the Ionic Deeplinker. 
*/ 
static forRoot(appRoot: any, 
       config: any = null, 
       deepLinkConfig: DeepLinkConfig = null): ModuleWithProviders { 

对于引导单页,您可以尝试IonicPageModule

@NgModule({ 
    imports: [IonicModule], 
    exports: [IonicModule] 
}) 
export class IonicPageModule { 

    static forChild(page: any): ModuleWithProviders { 

的进口改为:

imports: [ 
    IonicPageModule.forChild(Login), 
    ] 

更新:

相关链接:IonicPageIonicPageModule

根据在discussion here中共享的google docs,这是在ionic 3中引入的,用于离子页面的延迟加载。

+0

为什么这个新页面正在创建。在此之前不在页面文件夹中? 甚至还没有发生在我的旧项目 –

+0

什么是您的离子版本? –

+0

现在2.2.2,之前是2.2.1 但现在已经更新。 –

相关问题