我收到一個錯誤 - 錯誤:NG0302:找不到管道“編號”!當我在我的 Ionic Framework Angular 應用程式的模態中使用它時。下面的代碼在父頁面和應用程式的其他地方作業正常,沒有任何管道宣告。它只是在模態中失敗。
{{ data.amount | number: '1.2-2'}}
我什至嘗試了以下方法,看看我是否可以以某種方式將我的金額轉換為小數點后兩位,或者可以通過管道輸入但沒有成功。
{{ data.amount*1.00 }}
uj5u.com熱心網友回復:
在不真正了解您的檔案結構的情況下,我認為正在發生以下情況,如果我錯了,請糾正我:
Pages-folder
- parent-page-folder
- parent.page.html
- parent.page.ts
- parent.page.scss
- parent.module.ts
- parent-routing.module.ts
- modal-component-folder
- modal.component.ts
- modal.component.html
- modal.component.scss
正如您通過這種結構看到的那樣,您的 modal.component 沒有模塊,因此沒有必要的匯入來使用 angular 的任何內置函式。您可以做的是創建一個 modal.module.ts 并匯入所需的模塊。它可能看起來像這樣:
父模塊:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { ParentPageRoutingModule } from './parent-routing.module';
import { ParentPage } from './parent.page';
import { ModalModule } from './modal/modal.module';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
ModalModule, // <-- needs to be declared in parent module
ParentPageRoutingModule,
],
declarations: [ParentPage]
})
export class ParentPageModule {}
和手動創建的模態模塊:
import { NgModule } from '@angular/core';
import { CommonModule } from '@angular/common';
import { FormsModule } from '@angular/forms';
import { IonicModule } from '@ionic/angular';
import { ModalComponent } from './modal.component';
@NgModule({
imports: [
CommonModule,
FormsModule,
IonicModule,
],
exports: [
CommonModule,
FormsModule,
IonicModule],
declarations: [ModalComponent]
})
export class ModalModule {}
希望這能讓您深入了解如何讓組件知道不同的功能,即使它們是內置的。
uj5u.com熱心網友回復:
為此找到了一個更簡單,更容易的解決方法 -
在我的 page.ts 檔案中 - 我從陣列中獲取金額值并使用 javascript toFixed 函式將我的金額轉換為 2 位小數。這并不理想,但它有效。要使用角度方式,它需要在很多地方匯入和宣告 DecimalPipe。
this.amount = this.amount.toFixed(2);
Angular 1.0 過去使用起來非常簡單。在那之后,它變成了一堆挫折。肯定是 React 中的下一個應用程式。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/485298.html
上一篇:IONIC/REACT第9:5行:期望一個賦值或函式呼叫,而是看到一個運算式@typescript-eslint/no-unused-expressions
