类型'typeof IonicModule'上不存在属性'forChild' [英] Property 'forChild' does not exist on type 'typeof IonicModule'

查看:842
本文介绍了类型'typeof IonicModule'上不存在属性'forChild'的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用离子cli使用此命令生成页面

I'm using the ionic cli to generate the page using this command

ionic generate page login
ionic g page login

然后我在浏览器中收到此错误

then i get this error in browser

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个项目。

also creating 4 items in login folder.

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

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

any body can solve this. here is 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 {}

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

if i remove this line , app works fine.

 IonicModule.forChild(Login),


推荐答案

IonicModule.forRoot(MyApp)

Github link 此处

Github link 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

For bootstrapping a single page you could try IonicPageModule.

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

   static forChild(page: any): ModuleWithProviders {

将您的导入更改为:

 imports: [
    IonicPageModule.forChild(Login),
  ]

更新:

相关链接: IonicPage
IonicPageModule

根据 google docs 此处讨论中分享在 ionic 3 中引入,用于延迟加载离子页面。

According to the google docs shared in discussion here this is introduced in ionic 3 for lazy loading of ionic pages.

这篇关于类型'typeof IonicModule'上不存在属性'forChild'的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆