如何解决无法在 NgModule 中声明“TimeAgoPipe”,因为它不是当前编译的一部分
我在执行 Angular 10
时在 ng build --prod
中遇到错误。它适用于 ng build
。
ERROR in src/app/app.module.ts:44:5 - error NG6001: Cannot declare 'TimeAgoPipe' in an NgModule as it's not a part of the current compilation.
44 TimeAgoPipe,~~~~~~~~~~~
node_modules/time-ago-pipe/time-ago.pipe.d.ts:3:22
3 export declare class TimeAgoPipe implements PipeTransform,OnDestroy {
~~~~~~~~~~~
'TimeAgoPipe' is declared here.
这是node_modules/time-ago-pipe/time-ago.pipe.d.ts
里面的文件
import { PipeTransform,ngzone,ChangeDetectorRef,OnDestroy } from "@angular/core";
import * as ɵngcc0 from '@angular/core';
export declare class TimeAgoPipe implements PipeTransform,OnDestroy {
private changeDetectorRef;
private ngzone;
private timer;
constructor(changeDetectorRef: ChangeDetectorRef,ngzone: ngzone);
transform(value: string): string;
ngOnDestroy(): void;
private removeTimer();
private getSecondsUntilUpdate(seconds);
static ɵfac: ɵngcc0.ɵɵFactoryDef<TimeAgoPipe,never>;
static ɵpipe: ɵngcc0.ɵɵPipeDefWithMeta<TimeAgoPipe,"timeAgo">;
}
//# sourceMappingURL=time-ago.pipe.d.ts.map
这就是我在 app.module.ts
文件中使用它的方式
import { NgModule } from '@angular/core';
import {TimeAgoPipe} from 'time-ago-pipe';
@NgModule({
declarations: [
TimeAgoPipe
],imports: [
FormsModule,],entryComponents: [LastseenDevicesComponent],bootstrap: [ AppComponent ],})
export class AppModule { }
我该如何解决这个问题?
解决方法
此软件包已 3 年未维护,我建议使用 https://www.npmjs.com/package/ngx-pipes#timeago,您可以在此处找到有关此问题的更多详细信息 https://github.com/AndrewPoyntz/time-ago-pipe/issues/33
此解决方案适用于某些人
...
import { TimeAgoPipe } from 'time-ago-pipe';
@Pipe({
name: 'timeAgo',pure: false
})
export class TimeAgoExtendsPipe extends TimeAgoPipe {}
@NgModule({
declarations: [
TimeAgoExtendsPipe,...
,
也将 TimeAgoPipe
添加到 exports
的 app.module
数组中。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。