-->

Ionic 3 Lazy Loading with amDateFormat pipe

2020-07-17 16:58发布

问题:

I am using Ionic3, and am in the process of converting to Lazy Loading in order to improve startup performance.

I am experiencing a problem with pipes after converting my ChatsPage to lazy loading. As you can see below, it is complaining about the use of the following line in my chats.html.

    <h3 class="chat-time">{{item.timestamp | amDateFormat: 'D MMM YYYY'}}</h3>
ERROR Error: Uncaught (in promise): Error: Template parse errors:
The pipe 'amDateFormat' could not be found ("item.memberId2 && !item.lastMsg_read2))}">{{item.lastMsg_text}}</p>
        <h3 class="chat-time">{{[ERROR ->]item.timestamp | amDateFormat: 'D MMM YYYY'}}</h3>
      </ion-item>

"): ng:///ChatsPageModule/ChatsPage.html@28:32
Error: Template parse errors:
The pipe 'amDateFormat' could not be found ("item.memberId2 && !item.lastMsg_read2))}">{{item.lastMsg_text}}</p>
        <h3 class="chat-time">{{[ERROR ->]item.timestamp | amDateFormat: 'D MMM YYYY'}}</h3>
      </ion-item>

Question

Any idea how to handle amDateFormat (angular2-moment) with lazy loading?

More info:

Your system information:

Cordova CLI: 6.4.0 
Ionic Framework Version: 3.0.1
Ionic CLI Version: 2.1.18
Ionic App Lib Version: 2.1.9
Ionic App Scripts Version: 1.3.0
ios-deploy version: Not installed
ios-sim version: Not installed
OS: macOS Sierra
Node Version: v6.9.4
Xcode version: Xcode 8.3.2 Build version 8E2002

回答1:

For lazy loading you need to add the module to imports of the page.module.ts.

import {MomentModule} from 'angular2-moment';

@NgModule({
  imports: [
    MomentModule
  ],