- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试创建一个显示随机文本和图片的 Android 应用程序 (Node.js + Ionic)(文本和图片的选择存储在数组中)。我正在尝试在我的手机上安装这个应用程序。该应用程序适用于 Chrome。
当我在命令提示符下输入 ionic serve 命令时,它在 Chrome 中完美运行,每次我按下一个按钮时,Random1 都会给出一个随机文本和一个随机图片,每次我按下一个按钮时,Random2 只会给出一个随机图片按钮。当我在命令提示符下输入“ionic cordova run android --prod --release”命令时,出现此错误:
[16:54:50] build prod started ...
[16:54:50] clean started ...
[16:54:50] clean finished in 6 ms
[16:54:50] copy started ...
[16:54:50] deeplinks started ...
[16:54:50] deeplinks finished in 84 ms
[16:54:50] ngc started ...
[16:55:02] typescript error
Type Random1Page in
C:/.../pages/random1/random1.ts is part of the declarations of 2 modules: AppModule in
C:/.../app/app.module.ts and
Random1PageModule in
C:/.../pages/random1/random1.module.ts!
Please consider moving Random1Page in
C:/.../pages/random1/random1.ts to a higher module that imports AppModule in
C:/.../app/app.module.ts and Random1PageModule in
C:/.../pages/random1/random1.module.ts. You
can also create a new NgModule that exports and includes Random1Pag
e in C:/.../pages/random1/random1.ts then import that NgModule in AppModule in
C:/.../app/app.module.ts and
Random1PageModule in
C:/.../pages/random1/random1.module.ts.
Typescript error - Error: The Angular AoT build failed. See the issues above
at C:/...\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:237:55
at step (C:/...\no
de_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:32:23)
at Object.next (C:/...\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:13:53)
at fulfilled (C:/...\node_modules\@ionic\app-scripts\dist\aot\aot-compiler.js:4:58)
at anonymous
我从 ionic 应用程序的文件夹中发出了这个命令。此文件夹包含以下文件夹:
这是发出此命令的正确文件夹吗?
随机1.ts:
import { Component } from '@angular/core';
import { IonicPage, NavController, NavParams } from 'ionic-angular';
import { Random2Page } from '../random2/random2';
@IonicPage()
@Component({
selector: 'page-random1',
templateUrl: 'random1.html',
})
export class Random1Page {
random1_arr: string[]= ["text1", "text2", "text3"];
random1_act: string;
image_arr: string[]= ["../assets/imgs/Pic1.jpg", "../assets/imgs/Pic2.jpg"];
image_act: string;
person_arr: string[]= ["person1", "person2"];
person_act: string;
person_not_act: string;
counter= 0;
constructor(public navCtrl: NavController, public navParams: NavParams) {
this.image_act= '';
let random_index= Math.floor(Math.random() * 2);
this.person_act= this.person_arr[random_index];
this.person_not_act= this.person_arr[random_index? 0: 1];
this.GenerateRandom1PicturePerson();
}
GenerateRandom1PicturePerson() {
this.random1_act= this.random1_arr[Math.floor(Math.random() * this.random1_arr.length)];
this.image_act= this.image_arr[Math.floor(Math.random() * this.image_arr.length)];
this.person_act= [this.person_not_act, this.person_not_act= this.person_act][0];
this.counter++;
if(this.counter >= 7) {
this.navCtrl.push(Random2Page);
}
}
}
应用程序模块.ts:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { HomePage } from '../pages/home/home';
import { ListPage } from '../pages/list/list';
import { Random1Page } from '../pages/random1/random1';
import { Random2Page } from '../pages/random2/random2';
import { LoggedinPage } from '../pages/loggedin/loggedin';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
@NgModule({
declarations: [
MyApp,
HomePage,
ListPage,
Random1Page,
Random2Page,
LoggedinPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp,
HomePage,
ListPage,
Random1Page,
Random2Page,
LoggedinPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
最佳答案
根据您的问题,我们无法确定您是否想要使用延迟加载页面。如果您确实想使用延迟加载的页面(这样做会提高应用程序的性能),那么以下步骤将帮助您解决问题。
如果您不想在您的应用中使用延迟加载页面,请改为查看@Sampath 的回答。
当您在任何页面顶部添加 @IonicPage()
时:
@IonicPage() // <-- Here!
@Component({
selector: 'page-random1',
templateUrl: 'random1.html',
})
export class Random1Page { ... }
意味着它将被延迟加载。您还应该在该页面的同一目录中有一个 random1.module.ts
文件,如下所示:
import { NgModule } from '@angular/core';
import { IonicPageModule } from 'ionic-angular';
import { Random1Page } from './random1';
@NgModule({
declarations: [
Random1Page,
],
imports: [
IonicPageModule.forChild(Random1Page),
],
})
export class Random1PageModule {}
正如您在最后一个文件中看到的,Random1Page
是 Random1PageModule
模块 的一部分。
现在回到您遇到的错误:
typescript error Type Random1Page in C:/.../pages/random1/random1.ts is part of the declarations of 2 modules: AppModule in C:/.../app/app.module.ts and Random1PageModule in C:/.../pages/random1/random1.module.ts!
因此,为了修复它,您需要从位于 app.module.ts
的 AppModule
中删除该页面(以及所有其他延迟加载的页面) > 文件:
import { BrowserModule } from '@angular/platform-browser';
import { ErrorHandler, NgModule } from '@angular/core';
import { IonicApp, IonicErrorHandler, IonicModule } from 'ionic-angular';
import { MyApp } from './app.component';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
@NgModule({
declarations: [
MyApp
// HomePage,
// ListPage,
// Random1Page, <-- Remove it from here
// Random2Page,
// LoggedinPage
],
imports: [
BrowserModule,
IonicModule.forRoot(MyApp),
],
bootstrap: [IonicApp],
entryComponents: [
MyApp
// HomePage,
// ListPage,
// Random1Page, <-- And also from here
// Random2Page,
// LoggedinPage
],
providers: [
StatusBar,
SplashScreen,
{provide: ErrorHandler, useClass: IonicErrorHandler}
]
})
export class AppModule {}
您可以在 Ionic 博客中找到有关延迟加载的更多信息:
关于angular - Typescript 错误 - Angular AoT 构建失败 - Node.js + Ionic 移动应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47853157/
我想在聚焦时使用 ion-input 更改 ion-item 内的 ion-label 颜色。 我可以使用 --highlight-color-focused: yellow; 更改 ion-item
我想用 ionic 3 ion-list (或任何在 Ionic 3 中有效的东西)来显示水平列表而不是典型的垂直列表。 寻找解决方案 没有大量的 css 或难以维护的代码。
我目前使用 ionic 和我的 cordova 插件同时开发一个应用程序。我想知道如何使用文件 plugins/fetch.json 从本地文件系统更新我的插件。有什么想法吗? 最佳答案 使用 ion
当我在 ionic 项目文件夹中运行 ionic link 命令时,我收到以下错误消息 “除非您在 Ionic 项目文件夹中,否则您无法运行此命令” 我的系统信息。 Cordova CLI:6.3.1
如何注释 ion-row这样它就可以填满剩余的空间? 对于以下示例,黄色行“内容”应展开,直到占用所有剩余(绿色)空间。 Example text
我正在尝试构建一个 ionic 应用程序,但是当我运行 npm run ionic:build -–prod 时,出现以下错误: npm run ionic:build -–prod npm ERR!
我想在 ion-footer-bar 中添加两个按钮,如图片,但我的代码无法正常工作。 Button 333333333 Button
请有人澄清一下我什么时候会使用 ion-nav-view反对 ion-view ?我正在学习 AngularJS/Ionic(我对 AngularJS 有基本的了解;并且想使用 Ionic 来增强它)
关闭。这个问题是opinion-based .它目前不接受答案。 想改善这个问题吗?更新问题,以便可以通过 editing this post 用事实和引文回答问题. 1年前关闭。 Improve t
item-avatar 在我的项目中不起作用,它根本不显示 item-avatar 元素。 Recent Conversations
我正在使用带有属性interface="popover"的ion-select。弹出窗口在 select 下方打开,这使得弹出窗口非常小。 我发现,如果 ion-select 中有 10 个或更多项目
我创建了一个带有电容器的新项目 ionic。我使用 ionic 选择,但我有一个新的 ionic 选择选项,带有大文本,而不是在输入中分布。 Plaga/Enfermedad Al
如何像 ionic 中的许多应用程序一样滑动切换段?我在 ionic 官方文档中找不到任何 api。我只能找到this有用的线程。 但它似乎并不完美。有更好的解决办法吗? ionic 信息: Cord
我正在开发一个登录表单,所以在我的 中我有一个 (用作登录表单的容器)我想垂直居中。我用 css flexbox 和其他 css 技巧尝试了不同的方法,但对我没有任何作用!该卡片保留在页面顶部。你
我想在 ionic 选择(组合框)更改时隐藏和显示文本框 例如我有: ionic 选择中的 1 和 2如果我选择 1 文本框将隐藏,如果我选择 2 文本框将出现 这是我当前的代码: .ts onCha
我尝试在 ionic 4 中使用 ion-button 实现一个按钮,但没有样式输出,问题出在哪里,求助。 最佳答案 请使用以下代码 这里是 ionic v4 按钮的文档。 https://beta
我有一个在 ionic serve 中运行良好的应用程序。我现在正在尝试创建一个构建——这通常有效,但今天我遇到了问题。 ionic package build ios --profile devel
我正在使用 Ionic 2,在我的应用程序中我正在创建一个表单,如果出现验证错误,信息图标将出现在相关输入字段的右侧。 HTML如下,
我正在与一个远程团队一起开发 Ionic 1 应用程序,最近我们的版本彼此不喜欢。我想知道我是否也一直在从事 Ionic 2 项目,无论出于何种原因,我的 CLI “认为”这些应用程序也是 Ionic
我需要禁用默认 ion-ripple-effect在“ ionic 按钮”中。 我无法禁用 pointer-events因为我需要它。 PS:我引用了以下帖子,但找不到适合 Ionic 4
我是一名优秀的程序员,十分优秀!