The ngx-uom library provide a service and a pipe that can be used to convert a given numeric value from an Unit Of Measure (uom) to a another one (Ex from millimiters to inches)
To install this library, run:
$ npm install ngx-uom --save
Once you have published your library to npm, you can import your library in any Angular application by running:
$ npm install ngx-uom
and then from your Angular AppModule
:
import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { AppComponent } from './app.component';
// Import your library
import { UomModule } from 'ngx-uom';
@NgModule({
declarations: [
AppComponent
],
imports: [
BrowserModule,
// Specify the UomModule as an import
UomModule.forRoot(),
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
uom pipe converts a given numeric value from an unit of measure to another one
{{value | uom : valueUom : desiredUom}}
<!-- You can now use the uom pipe in the template -->
<!-- in this example the value temperature is to be given in celsius degrees and we want to display as
<!-- kelvin degrees -->
<h1>
{{title}}
</h1>
<div>{{temperature | uom : 'c' : 'k'}}</div>
MIT © Rossano Catellani