Ionic2 IonicPage不工作

Ionic2 IonicPage不工作,ionic2,ionic3,Ionic2,Ionic3,我在使用说明 但我得到了以下错误: 错误:/app/src/pages/subscribe channel/subscribe-channel.ts有一个 @IonicPage装饰程序, 但它在/app/src/pages/subscribe channel/subscribe-channel.module.ts处没有相应的“NgModule” 具体来说,我在文件中做了如下更改: 添加了IonicPageModule.forChild(SubscribeChannelPage) 在组件上添加了@

我在使用说明

但我得到了以下错误:

错误:/app/src/pages/subscribe channel/subscribe-channel.ts有一个 @IonicPage装饰程序, 但它在/app/src/pages/subscribe channel/subscribe-channel.module.ts处没有相应的“NgModule”

具体来说,我在文件中做了如下更改:

  • 添加了IonicPageModule.forChild(SubscribeChannelPage)

  • 在组件上添加了
    @IonicPage()
    ,即
    SubscribeChannelPage

  • 我无法共享代码示例,因为它是更大应用程序的一部分

    此处报告了类似的错误:

    IonicPage在建议的答案中被注释掉,以消除此错误。然而,我正在尝试使用IonicPage,并想知道如何使其工作

    这里是
    订阅频道.ts

    import { Component, OnInit } from '@angular/core';
    import { NavController, NavParams } from 'ionic-angular';
    import { IonicPage } from 'ionic-angular';
    
    @IonicPage()
    @Component({
        selector: 'page-subscribe-channel',
        templateUrl: 'subscribe-channel.html'
    })
    export class SubscribeChannelPage implements OnInit {
    
      constructor() {
      }
    
      ngOnInit() {
      }
    
    }
    
    import { NgModule, ErrorHandler, APP_INITIALIZER } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { StatusBar } from '@ionic-native/status-bar';
    import { SplashScreen } from '@ionic-native/splash-screen';
    import { HttpModule } from '@angular/http';
    import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
    import { IonicPageModule } from 'ionic-angular';
    import { MyApp } from './app.component';
    import { SubscribeChannelPage } from '../pages/subscribe-channel/subscribe-channel';
    
    @NgModule({
      declarations: [
        MyApp,
        SubscribeChannelPage
      ],
      imports: [
        BrowserModule,
        HttpModule,
        IonicModule.forRoot(MyApp),
        IonicPageModule.forChild(SubscribeChannelPage)
      ],
      bootstrap: [IonicApp],
      entryComponents: [
        MyApp,
        SubscribeChannelPage
      ],
      providers: [
        StatusBar,
        SplashScreen,
        { provide: ErrorHandler, useClass: IonicErrorHandler }
      ]
    })
    export class AppModule { }
    
    下面是
    app.modules.ts

    import { Component, OnInit } from '@angular/core';
    import { NavController, NavParams } from 'ionic-angular';
    import { IonicPage } from 'ionic-angular';
    
    @IonicPage()
    @Component({
        selector: 'page-subscribe-channel',
        templateUrl: 'subscribe-channel.html'
    })
    export class SubscribeChannelPage implements OnInit {
    
      constructor() {
      }
    
      ngOnInit() {
      }
    
    }
    
    import { NgModule, ErrorHandler, APP_INITIALIZER } from '@angular/core';
    import { BrowserModule } from '@angular/platform-browser';
    import { StatusBar } from '@ionic-native/status-bar';
    import { SplashScreen } from '@ionic-native/splash-screen';
    import { HttpModule } from '@angular/http';
    import { IonicApp, IonicModule, IonicErrorHandler } from 'ionic-angular';
    import { IonicPageModule } from 'ionic-angular';
    import { MyApp } from './app.component';
    import { SubscribeChannelPage } from '../pages/subscribe-channel/subscribe-channel';
    
    @NgModule({
      declarations: [
        MyApp,
        SubscribeChannelPage
      ],
      imports: [
        BrowserModule,
        HttpModule,
        IonicModule.forRoot(MyApp),
        IonicPageModule.forChild(SubscribeChannelPage)
      ],
      bootstrap: [IonicApp],
      entryComponents: [
        MyApp,
        SubscribeChannelPage
      ],
      providers: [
        StatusBar,
        SplashScreen,
        { provide: ErrorHandler, useClass: IonicErrorHandler }
      ]
    })
    export class AppModule { }
    
    @gerdi,答案中的建议有助于避免编译错误。然而,深层链接仍然不起作用,它需要默认页面

    仅供参考,deep链接先前使用了
    app.module.ts
    中的以下代码。然而,我正在尝试IonicPage,假设它是未来更好的选择

            IonicModule.forRoot(MyApp, {}, {
              links: [
                { component: SubscribeChannelPage, name: 'subscribe', segment: 'subscribe/:channelId' },
              ]
            }),
    

    为了使用
    @IonicPage()
    ,添加装饰器的“组件页”需要有一个连接的模块

    你得到的错误基本上是说

    您已经添加了@IonicPage()装饰器,但没有与此组件关联的模块。您需要包括一个subscribe-channel.module.ts文件,该文件在其自己的模块作用域中声明此组件

    因此,您需要添加一个
    subscribe channel.module.ts
    ,它是一个模块的声明

    为了更好地理解这一点,您可以进入终端,生成一个新模板,并查看它添加的文件

    >_ ionic generate page foobar
    
    在foobar文件夹下,您将看到4个文件,其中一个是
    foobar.module.ts
    ,这是模块声明

    仅供参考:你需要改变

    import { IonicModule } from 'ionic-angular';
    

    在生成的模板中。关于这个新的闪亮的东西,似乎还有一些问题

    然而,深层链接仍然不起作用,它需要默认页面。 仅供参考,deep链接在app.module.ts中使用了以下代码。然而,我正在尝试IonicPage,假设它是未来更好的选择

            IonicModule.forRoot(MyApp, {}, {
              links: [
                { component: SubscribeChannelPage, name: 'subscribe', segment: 'subscribe/:channelId' },
              ]
            }),
    
    对于深度链接,您现在必须在所需的
    IonicPage()
    decorator中设置它

    除去

    links: [
                { component: SubscribeChannelPage, name: 'subscribe', segment: 'subscribe/:channelId' },
              ]
    
    这是在ionic 3.x中引入IonicPage之前

    尝试:

    订阅频道.ts。 示例Url为:

     http://localhost:8101/#/subscribe/:channelId
    

    模块的文件名与组件相同:
    -
    login.ts

    -
    login.module.ts


    该模块需要命名为
    login
    ,以便进行通信。

    您可以添加subscribe-channel.module.ts文件吗?您的答案有助于避免我在问题中报告的错误。然而,深度链接仍然不起作用。转到默认页面。IonicPage文档中提到了这一点,我也在尝试同样的方法。然而,它不起作用。早些时候,我面临着编译问题,正如@gerdi所建议的那样,这些问题已经得到了解决。尽管如此,我还是不知道为什么深度链接不起作用。这是我发现的一个样本项目。它实现了您正在尝试的功能。只有在没有#符号的情况下才能产生相同的效果吗?