IonicPage无法正常工作

时间:2017-04-18 10:20:47

标签: ionic2 ionic3

我正在IonicPage Documentation

使用说明

但是我收到以下错误:

  

错误:/app/src/pages/subscribe-channel/subscribe-channel.ts有一个   @IonicPage装饰,       但它在/app/src/pages/subscribe-channel/subscribe-channel.module.ts

没有相应的“NgModule”

具体而言,我在文档中规定了以下更改:

  1. 添加了@Override public boolean test(final SAMRecord rec) { {if ("" != null) return rec.getDuplicateReadFlag();}}

  2. 在组件上添加了IonicPageModule.forChild(SubscribeChannelPage),即@IonicPage()

  3. 我无法共享代码示例,因为它是较大应用程序的一部分。

    此处报告了类似的错误: Page has a @IonicPage decorator, but it does not have a corresponding "NgModule"

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

    以下是SubscribeChannelPage

    subscribe-channel.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() { } }

    app.modules.ts

    @gerdi,答案中的建议有助于避免编译错误。但是,深层链接仍然不起作用,它需要默认页面。

    仅供参考,深层链接在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 { } 中使用以下代码时工作得更早。但是,我正在尝试IonicPage,假设它是未来更好的选择。

    app.module.ts

3 个答案:

答案 0 :(得分:4)

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

你得到的错误基本上是在说。

  

您已添加@IonicPage()装饰器,但此组件没有关联的模块。您需要包含一个subscribe-channel.module.ts文件,该文件在其自己的模块范围内声明此组件。

所以你需要添加subscribe-channel.module.ts这是模块的声明。

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

>_ ionic generate page foobar

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

仅供参考:您需要更改

import { IonicModule } from 'ionic-angular';

import { IonicPageModule } from 'ionic-angular';

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

答案 1 :(得分:0)

  

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

对于深层链接,您现在必须在所需ionic pageIonicPage()装饰器中进行设置。

删除

links: [
            { component: SubscribeChannelPage, name: 'subscribe', segment: 'subscribe/:channelId' },
          ]

因为这是在离子3.x中引入IonicPage之前的

尝试:

@IonicPage({
  name: 'SubscribeChannelPage',
  segment: 'subscribe/:channelId'
})
subscribe-channel.ts 中的

。 示例Url将是:

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

答案 2 :(得分:0)

模块的文件名与组件相同:
- login.ts
- login.module.ts
该模块需要命名为login才能对应。

相关问题