Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ionic-framework/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 页面有一个@IonicPage装饰器,但它没有相应的";NgModule";_Angular_Ionic Framework - Fatal编程技术网

Angular 页面有一个@IonicPage装饰器,但它没有相应的";NgModule";

Angular 页面有一个@IonicPage装饰器,但它没有相应的";NgModule";,angular,ionic-framework,Angular,Ionic Framework,我在爱奥尼亚从事网页导航工作。使用爱奥尼亚发球后,我出现以下错误: 扩展名为.ts的页面有@IonicPage装饰器,但没有相应的“NgModule” 有人能解释我为什么会出现此错误。我刚刚从组件页面中删除了以下属性: <!-- /src/app/pages/{page-name}/{page-name.ts} --> @IonicPage() @IonicPage() 其他离子示例页面甚至没有。似乎ionic CLI已经过时了(我猜您是用它来生成页面组件的)。今天我在生成页面

我在爱奥尼亚从事网页导航工作。使用
爱奥尼亚发球
后,我出现以下错误:

扩展名为.ts的页面有@IonicPage装饰器,但没有相应的“NgModule”


有人能解释我为什么会出现此错误。

我刚刚从组件页面中删除了以下属性:

<!-- /src/app/pages/{page-name}/{page-name.ts} -->
@IonicPage()

@IonicPage()

其他离子示例页面甚至没有。似乎ionic CLI已经过时了(我猜您是用它来生成页面组件的)。

今天我在生成页面时遇到了同样的问题。这几天前没有发生


我删除了页面的
NgModule
,然后删除了
@IonicPage()
decorator,它恢复了功能。虽然有点黑,但它现在已经启动并运行了…

这是因为
@IonicPage()
装饰器用于深度链接,这将在爱奥尼亚的深度链接系统中注册页面

如果您不想在该页面上有深度链接,可以删除装饰程序

或者,您可以使用以下代码在
YOURPAGE.module.ts
中注册该页面:

@NgModule({
  declarations: [
    MyPage
  ],
  imports: [
    IonicPageModule.forChild(MyPage)
  ],
  entryComponents: [
    MyPage
  ]
})

如果要使用深度链接,请先阅读

现在让我们看一个添加深度链接页面的示例:

这是我们的src文件夹结构:

-src
 --app
 --assets
 --pages
    --home
       *home.html
       *home.scss
       *home.ts
 --thems
 *some file we not working with them in here
-src
 --app
 --assets
 --pages
    --home
       *home.html
       *home.scss
       *home.ts
    --show
       *show.html
       *show.scss
       *show.ts
 --thems
 *some file we not working with them in here
要添加页面,请在应用程序文件夹中使用以下命令:

$ ionic g page show 
显示的是页面名称。 现在这是我们的src文件夹结构:

-src
 --app
 --assets
 --pages
    --home
       *home.html
       *home.scss
       *home.ts
 --thems
 *some file we not working with them in here
-src
 --app
 --assets
 --pages
    --home
       *home.html
       *home.scss
       *home.ts
    --show
       *show.html
       *show.scss
       *show.ts
 --thems
 *some file we not working with them in here
如果您现在在应用程序文件夹中使用以下命令运行应用程序:

$ ionic serve
您会得到如下错误:

-src
     --app
     --assets
     --pages
        --home
           *home.html
           *home.scss
           *home.ts
        --show
           *show.html
           *show.scss
           *show.ts
           *show.module.ts
     --thems
     *some file we not working with them in here
/path/to/app/src/pages/show/show.ts有一个@IonicPage装饰器,但它 在上没有相应的“NgModule” /path/to/app/src/pages/show/show.module.ts

现在,您应该在show文件夹中创建名为
show.module.ts
(错误的地方是这样写的)的文件,然后我们的src文件夹结构应该如下所示:

-src
     --app
     --assets
     --pages
        --home
           *home.html
           *home.scss
           *home.ts
        --show
           *show.html
           *show.scss
           *show.ts
           *show.module.ts
     --thems
     *some file we not working with them in here
这是
show.module.ts
文件的内容:

import { NgModule } from '@angular/core';
import {IonicPageModule} from 'ionic-angular';

import { ShowPage } from './show';

@NgModule({
  declarations: [
    ShowPage
  ],
  imports: [
    IonicPageModule.forChild(ShowPage)
  ],
  entryComponents: [
    ShowPage
  ]
})
export class ShowPageModule {}
完成了。 使用
爱奥尼亚服务运行应用程序
,错误消失

您可以使用导航到新页面

goToMyPage() {
    // go to the ShowPage component
    this.navCtrl.push('ShowPage');
  }

.

您必须确保爱奥尼亚正在查找的模块文件名与您的文件名匹配。
我也遇到了同样的问题,因为爱奥尼亚正在寻找“home.modules.ts”,而我有“home.module.ts”(最后没有s),因此爱奥尼亚找不到@NgModule装饰程序。

在我的情况下,我的文件名不区分大小写,我有News.ts&News.module.ts


现在,在.ts页面中运行fine

添加以下代码,将单词“name”替换为您命名的页面。不要忘记在app.module.ts页面中添加新页面

import { Component } from '@angular/core';
import { NavController } from 'ionic-angular';

@Component({
selector: 'page-name',
templateUrl: 'name.html',
})

export class NamePage {
   constructor(public navCtrl: NavController) {
  }
}

这是因为@IonicPage()decorator用于深度链接和延迟加载,因此要实现这一点,您需要一个专用模块来加载该页面所需的所有组件。请看爱奥尼亚的文档:


例如,当您使用Ionic CLI添加页面时

离子生成页面新建页面

然后它自动生成文件newPage.module.ts,并在newPage.ts内生成一行文本,如下所示:

@IonicPage()

那么,您必须删除newPage.module.ts并从newPage.ts中删除@IonicPage()

然后打开app.module.ts并在声明和条目组件中添加新页面

仅使用:

import { IonicPage } from 'ionic-angular';

@IonicPage()

@Component({
  selector: 'page-abc',
  templateUrl: 'abc.html',
})

当您使用angular 2+命名约定时,可能会出现此问题,以前它类似于
my app.component.ts
,更新为ionic 3命名约定
my app.ts
,如果需要,您可以使用
@IonicPage()
装饰器。

@IonicPage()用于深度链接。如果你想在你的应用程序中使用deeplinking,你需要做ngModule的事情。我想让deeplinking用于延迟加载,但它对我不起作用。有什么信息吗?如果我们不能明确定义模块名,那就太尴尬了。正因为如此,我将无法为我当前的项目受益于延迟加载。我不想做那么多的重构,所以,如果没有任何组件用@IonicPage()修饰会发生什么?什么都不会发生,应用程序将在应用程序初始化时加载所有组件。如果你做一个离子服务并打开开发工具,你会看到组件/文件被加载。这是一个非常糟糕的做法。始终为页面使用单独的模块进行延迟加载。否则,你的应用程序启动时间将非常长