gpt4 book ai didi

javascript - *ng-if 不在 ionic 5 中的 ion-modal 内部工作

转载 作者:行者123 更新时间:2023-12-04 14:37:09 24 4
gpt4 key购买 nike

当我尝试调用具有 *ng-If 的 ion-modal 时,我正在使用 ionic 5 构建移动应用程序在里面,我会得到这个错误

Can't bind to 'ngIf' since it isn't a known property of 'ion-header'.
modal是comment.page.ts中的一个comment section,这里是comment.page.html的代码
<ion-header class="ion-no-border" *ngIf="!isLoading">
<ion-toolbar>
<ion-title class="centerAM">{{no_comm | shortNumber}} comment{{no_comm>1?'s':''}}</ion-title>
</ion-toolbar>
</ion-header>

<ion-content>
....
这是 comment.module.ts 的代码
import { NgModule } from '@angular/core';
import { IonicModule } from '@ionic/angular';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { NgxEmojModule } from 'ngx-emoj';

import { CommentPageRoutingModule } from './comment-routing.module';
import { CommentPage } from './comment.page';
import { PipesModule } from '../../pipes/pipes.module';

@NgModule({
imports: [
CommonModule,
NgxEmojModule,
PipesModule,
FormsModule,
IonicModule,
CommentPageRoutingModule
],
schemas: [],
declarations: [ CommentPage]
})
export class CommentPageModule {}
这是从 home.page.ts 调用模态的函数
async CommentModal(i, id) {
const modal = await this.modalCtrl.create({
component: CommentPage,
componentProps:{id},
swipeToClose: true,
cssClass: 'comment-modal'
});
await modal.present();
return
}
如果我应该在 home.module.ts 或 app.module.ts 中添加comment.module.ts,当页面加载时,它将自动加载模态而不需要用户单击任何内容,并且我还从路线,它没有用,请问我做错了什么

最佳答案

您的模块很可能是延迟加载的。在那种情况下 the docs建议您在需要此模态的模块内部导入模态模块(CommentPageModule)。
换句话说,您需要:

...
@NgModule({
imports: [
...
CommentPageModule, // <--- here
]
...
export class YourMainModule {}
否则,模态组件不会完全加载。
从文档中引用:

When lazy loading a modal, it's important to note that the modal will not be loaded when it is opened, but rather when the module that imports the modal's module is loaded.

关于javascript - *ng-if 不在 ionic 5 中的 ion-modal 内部工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/63396846/

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