How to use pipes in Component

前端 未结 3 1141
名媛妹妹
名媛妹妹 2020-12-09 16:20

I want to use the datePipe in my component. I followed the instructions here but I am met with

Error: StaticInjectorError[DatePipe]: 
StaticInjectorError[Da         


        
3条回答
  •  天涯浪人
    2020-12-09 16:52

    Pipes, unlike Services, are not injectable. In order to use pipe in a component, you need to create new instance of it:

    ngOnInit() {
        console.log(new DatePipe().transform(this.currentDate, 'YYYY-MM-DDTHH:mm'));
    }
    

提交回复
热议问题