Angular 2+ How do you use Date pipe in typescript

  • fennng 

Well, I was wrong in my last post. It’s possible to use a pipe in your type script code. The problem with the [value] attribute setting the reactive from control pipe is that it will not update once the data changed.

It’s better to pipe the data in the type script.

In the following code, createdDate is piped. You will need to import the DatePipe module. I use a VSCode extension to do this for me.

this.organizationStore.firstOrganization.subscribe(x => {
      if (x) {
        this.organization = x;
          domain: x.get('domain'),
          address: x.get('address'),
          phone: x.get('phone'),
          isActive: x.get('isActive'),
          licenseId: x.get('licenseId'),
          name: x.get('name'),
          description: x.get('description'),
          logoBase64: x.get('logoBase64'),
          createdDate: new DatePipe('en-NZ').transform(x.get('createdDate')),
          modifiedDate: x.get('modifiedDate'),
          createdBy: x.get('createdBy'),
          modifiedBy: x.get('modifiedBy')