iT邦幫忙

0

Ionic4/ Angular 7 app.module 的NgModule設定問題

大家好,我最近在寫IonicFramwork但由於對Angular比較陌生,所以希望有人能解答一下以下問題:

我目前有 Home.page, headerComponent, filterModal.page, 打算在HomePage中插入HeaderComponent,而header中有button 并通過ModalController打開 filterModal。 但我不太明白 app.module.ts 要如何設定,以下是目前設定:

**app.modules.ts**
@NgModule({
  declarations: [
    ...
    filterModal // need to remove if build in --prod
  ],
  entryComponents: [filterModal],
**headerComponent.ts**
import {filterModal} from '....';

async show(){
    this.modal = await this.modalCtrl.create({
      component: filterModal
    })
    return await this.modal.present();
  }

在上面的設定當中,我可以用 serve 在localhost 在browser 正常顯示,但當用build --prod時就出現 is part of the declarations of 2 modules:. 的error。
當我把filterModal從app.modules中我declarations刪掉才能正常Build,但在browser 中出現 FilterPage is not part of any NgModule or the module has not been imported into your module. 的error。

P.S. FilterModal只會用在HomePage 其他頁面不會用。

請問一下是錯在哪?

lolis iT邦新手 5 級 ‧ 2019-12-27 17:34:40 檢舉
我猜測下,你的Home.page所在文件夾是否有module.ts? 如果有的話,請將filterModal.component引入進至Home.module.ts的declarations内。
圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友回答

立即登入回答