import { Component, OnInit, Input, Output, EventEmitter, OnChanges } from '@angular/core'; import { FormBuilder, FormGroup, Validators, FormControl } from '@angular/forms'; @Component({ selector: 'hbor-postotak', templateUrl: './postotak.component.html', styleUrls: ['./postotak.component.css'] }) export class PostotakComponent implements OnInit, OnChanges { @Output() onPostotakChange: EventEmitter = new EventEmitter(); @Input() disabled = false; @Input() placeholder = 'Postotak'; @Input() floatLabel = 'auto'; @Input() errorMessageRequired = 'Polje je obavezno'; @Input() errorMessageCustom = ''; @Input() hborFormControl: FormControl; @Input() width = 180; @Input() max = 999; @Input() min = -999; @Input() required = true; @Input() mask = { prefix: '', suffix: '%', thousands: '', decimal: ',', allowNegative: true }; value; constructor() { } ngOnInit() { if (this.hborFormControl === undefined) { this.hborFormControl = new FormControl([{ value: '', disabled: this.disabled }]); } this.hborFormControl.valueChanges.subscribe(() => { this.onPostotakChange.emit(this.hborFormControl.value) }) } ngOnChanges() { } calculate(value): number { return value * 100; } }