Javascript 如何使用角管将日期添加到我的日期中?
我试图在约会时用管道增加一定的天数 所以我创造了管道Javascript 如何使用角管将日期添加到我的日期中?,javascript,angular,pipe,Javascript,Angular,Pipe,我试图在约会时用管道增加一定的天数 所以我创造了管道 import { Pipe, PipeTransform } from '@angular/core'; import * as moment from 'moment/moment'; @Pipe({ name: 'DataEncerramento' }) export class DataEncerramentoPipe implements PipeTransform { transform(dataAgendamento:
import { Pipe, PipeTransform } from '@angular/core';
import * as moment from 'moment/moment';
@Pipe({
name: 'DataEncerramento'
})
export class DataEncerramentoPipe implements PipeTransform {
transform(dataAgendamento: any, prazo: any ): any {
if (dataAgendamento) {
return moment(dataAgendamento).add(prazo, 'days');
}
return null;
}
}
在我的模板上试过
<p-column header="Data de encerramento" [style]="{ width: '200px' }">
<ng-template let-solicitacao="rowData" pTemplate="body">
<p *ngIf="solicitacao.dataAgendamento; else naoAgendada">
{{ solicitacao.DataEncerramento | DataEncerramentoPipe: 'solicitacao.dataAgendamento': 'solicitacao.prazo' }}
</p>
<ng-template #naoAgendada>
<p>Não agendada</p>
</ng-template>
</ng-template>
</p-column>
即使我在模块中导入了此管道。根据管道定义:
@Pipe({
name: 'DataEncerramento'
})
在HTML中使用相同的名称:
DataEncerramento
notdataencerramentoppe
您的管道名称是DataEncerramento
notdataencerramentoppe
@Pipe({
name: 'DataEncerramento'
})