gpt4 book ai didi

ionic2 - ionic 页不工作

转载 作者:行者123 更新时间:2023-12-01 12:21:53 25 4
gpt4 key购买 nike

我正在使用 IonicPage Documentation 的说明

但我收到以下错误:

Error: /app/src/pages/subscribe-channel/subscribe-channel.ts has a @IonicPage decorator, but it does not have a corresponding "NgModule" at /app/src/pages/subscribe-channel/subscribe-channel.module.ts



具体来说,我做了文档中规定的以下更改:
  • 已添加 IonicPageModule.forChild(SubscribeChannelPage)
  • 已添加 @IonicPage()在组件上,即 SubscribeChannelPage

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

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

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

    这里是 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
    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,答案中的建议有助于避免编译错误。但是,深层链接仍然不起作用,它需要到默认页面。

    仅供引用,深层链接之前在 app.module.ts 中使用以下代码工作.但是,我正在尝试 IonicPage 假设它是 future 的更好选择。
            IonicModule.forRoot(MyApp, {}, {
    links: [
    { component: SubscribeChannelPage, name: 'subscribe', segment: 'subscribe/:channelId' },
    ]
    }),

    最佳答案

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

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

    You have added the @IonicPage() decorator but there is no associated module for this component. You need to include a subscribe-channel.module.ts file that declares this component in its own module scope.



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

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

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

    仅供引用:你需要改变
    import { IonicModule } from 'ionic-angular';


    import { IonicPageModule } from 'ionic-angular';

    在生成的模板中。这个新的 Shiny 的东西似乎仍然存在一些问题

    关于ionic2 - ionic 页不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43469511/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com