Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <app-custom-label value="10000" title="My Title for a Currency render" datatype="currency" param="EUR"></app-custom-label>
- <app-custom-label value="01.10.1980" title="My Title for a Date render" datatype="date" param="dd MMMM"></app-custom-label>
- <h1>{{ title }}</h1>
- <label> {{ value }} </label>
- import { Component, Input, OnInit } from '@angular/core';
- import { DataType } from './type';
- import { CurrencyPipe, DatePipe } from '@angular/common';
- import { registerLocaleData } from '@angular/common';
- import localeDe from '@angular/common/locales/de';
- import localeDeExtra from '@angular/common/locales/extra/de';
- registerLocaleData(localeDe, 'de-DE', localeDeExtra);
- @Component({
- selector: 'app-custom-label',
- templateUrl: './custom.label.component.html'
- })
- export class CustomLabelComponent implements OnInit {
- @Input() value: string;
- @Input() title: string;
- @Input() datatype: DataType;
- @Input() param: string;
- constructor() {}
- ngOnInit(){
- if (this.datatype === "currency") {
- this.value = (new CurrencyPipe('de-DE')).transform(this.value, this.param, true);
- } else if (this.datatype === "date") {
- this.value = (new DatePipe('de-DE')).transform(this.value, this.param);
- }
- }
- }
Add Comment
Please, Sign In to add comment