Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to use datepipe in ts file

// Since CommonModule does not export it as a provider you'll have to do it yourself. This is not very complicated.

//1) Import DatePipe:

import { DatePipe } from '@angular/common';
// 2) Include DatePipe in your module's providers:

NgModule({
  providers: [DatePipe]
})
export class AppModule {
}
// or component's providers:

@Component({
  selector: 'home',
  styleUrls: ['./home.component.css'],
  templateUrl: './home.component.html',
  providers: [DatePipe]
})
export class HomeComponent {
...
// 3) Inject it into your component's constructor like any other service:

constructor(private datePipe: DatePipe) {
}
// 4) Use it:

ngOnInit() {
    this.time = this.datePipe.transform(new Date());
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: javascript remove extension from filename 
Javascript :: js go to previous page 
Javascript :: javascript int to float 
Javascript :: node get all files in folder 
Javascript :: generate random character in javascript 
Javascript :: onclick for dynamically created element jquery 
Javascript :: ERROR in ./server/server.js Module build failed (from ./node_modules/babel-loader/lib/index.js): 
Javascript :: one year ago javascript date 
Javascript :: jquery get the length of input text 
Javascript :: disable eslint for line 
Javascript :: return json with jango 
Javascript :: unsplash api javascript example 
Javascript :: js format number thousands separator 
Javascript :: npx react 
Javascript :: remove and add active class with jquery 
Javascript :: addclass js vanilla 
Javascript :: command to create react app 
Javascript :: onclick open modal jquery 
Javascript :: react native clear cach 
Javascript :: javascript backticks and if statements 
Javascript :: ng serve host 0.0.0.0 
Javascript :: sort array by date moment 
Javascript :: sleep in react 
Javascript :: jquery convert a string to an array 
Javascript :: numero aleatorio js 
Javascript :: js explode equivalent 
Javascript :: react native rotate image 
Javascript :: javascript open url 
Javascript :: javascript trim newline 
Javascript :: show password on click button jquery 
ADD CONTENT
Topic
Content
Source link
Name
1+4 =