Guest User

Untitled

a guest
Feb 17th, 2019
69
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.21 KB | None | 0 0
  1. <app-custom-label value="10000" title="My Title for a Currency render" datatype="currency" param="EUR"></app-custom-label>
  2.  
  3. <app-custom-label value="01.10.1980" title="My Title for a Date render" datatype="date" param="dd MMMM"></app-custom-label>
  4.  
  5. <h1>{{ title }}</h1>
  6. <label> {{ value }} </label>
  7.  
  8. import { Component, Input, OnInit } from '@angular/core';
  9. import { DataType } from './type';
  10. import { CurrencyPipe, DatePipe } from '@angular/common';
  11. import { registerLocaleData } from '@angular/common';
  12. import localeDe from '@angular/common/locales/de';
  13. import localeDeExtra from '@angular/common/locales/extra/de';
  14.  
  15. registerLocaleData(localeDe, 'de-DE', localeDeExtra);
  16.  
  17. @Component({
  18. selector: 'app-custom-label',
  19. templateUrl: './custom.label.component.html'
  20. })
  21. export class CustomLabelComponent implements OnInit {
  22. @Input() value: string;
  23. @Input() title: string;
  24. @Input() datatype: DataType;
  25. @Input() param: string;
  26.  
  27.  
  28. constructor() {}
  29.  
  30. ngOnInit(){
  31. if (this.datatype === "currency") {
  32. this.value = (new CurrencyPipe('de-DE')).transform(this.value, this.param, true);
  33. } else if (this.datatype === "date") {
  34. this.value = (new DatePipe('de-DE')).transform(this.value, this.param);
  35. }
  36. }
  37. }
Add Comment
Please, Sign In to add comment