I have two inputs for the user. The first input is the main number. The second input is the number of zeroes behind the main number.
The basic {{ mainNumber | number: '1.5'}}works. Here I will have five zeroes behind the main number. But I want that 5 to be dynamic, to be what the user has input in the second field.
This is the component.html:
Number <input type="number" [(ngModel)]="mainNumber" placeholder="Enter the number">
Zero: <input type="number" [(ngModel)]="zeroNumber" placeholder="Enter the zero"> <br>
<hr>
<b> Number: </b>{{mainNumber}}
<b> Zero: </b> {{zeroNumber}} <br>
<!-- {{ mainNumber | number: '1.10'}} -->
Final number: {{ mainNumber | mojpipe }}
This is the component.ts:
import { Component } from '@angular/core';
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.css']
})
export class AppComponent {
mainNumber: number = 0;
zeroNumber: number = 0;
title = 'shopping-project';
}
This is the custom pipe I tried to build, mypipe.ts:
import { Pipe, PipeTransform } from '@angular/core';
@Pipe({ name: 'mojpipe' })
export class AddZero implements PipeTransform{
testTwo: number = 1;
transform(size: number){
return (size + "."+ this.testDva);
};
}