Primitives
A meter is a visual representation of a value within a range.
import { Component, signal } from "@angular/core";
import {
NgpMeter,
NgpMeterIndicator,
NgpMeterLabel,
NgpMeterTrack,
NgpMeterValue,
} from "ng-primitives/meter";
@Component({
selector: "app-meter",
imports: [
NgpMeter,
NgpMeterLabel,
NgpMeterValue,
NgpMeterIndicator,
NgpMeterTrack,
],
template: `
<div [ngpMeterValue]="value()" ngpMeter>
<span ngpMeterLabel>Label</span>
<span ngpMeterValue>{{ value() }}%</span>
<div ngpMeterTrack>
<div ngpMeterIndicator></div>
</div>
</div>
`,
styles: `
[ngpMeter] {
display: grid;
grid-template-columns: 1fr 1fr;
grid-row-gap: 0.5rem;
width: 200px;
box-sizing: border-box;
padding: 0.5rem;
}
[ngpMeterLabel] {
color: var(--ngp-text-emphasis);
font-size: 14px;
font-weight: 600;
}
[ngpMeterValue] {
color: var(--ngp-text-secondary);
font-size: 14px;
font-weight: 500;
text-align: right;
grid-column-start: 2;
text-align: end;
}
[ngpMeterTrack] {
grid-column: 1 / 3;
overflow: hidden;
background-color: var(--ngp-background);
box-shadow: var(--ngp-shadow-border);
border-radius: 4px;
height: 8px;
}
[ngpMeterIndicator] {
background-color: var(--ngp-background-success);
height: 100%;
transition: width 0.2s ease-in-out;
inset-inline-start: 0px;
border-radius: 4px;
}
`,
})
export default class MeterExample {
/** The value of the meter. */
value = signal(30);
}
Import the Meter primitives from ng-primitives/meter
.
import {
NgpMeter,
NgpMeterValue,
NgpMeterIndicator,
NgpMeterTrack,
NgpMeterLabel,
} from 'ng-primitives/meter';
Assemble the meter directives in your template.
<div ngpMeter>
<span ngpMeterLabel>Label</span>
<span ngpMeterValue>Value</span>
<div ngpMeterTrack>
<div ngpMeterIndicator></div>
</div>
</div>
Create a reusable component that uses the NgpMeter
directive.
import { Component } from '@angular/core';
import { Meter } from './meter';
@Component({
selector: 'app-root',
imports: [Meter],
template: `
<app-meter label="Label" value="40" />
`,
})
export default class App {}
Generate a reusable meter component using the Angular CLI.
ng g ng-primitives:primitive meter
path
: The path at which to create the component file.prefix
: The prefix to apply to the generated component selector.componentSuffix
: The suffix to apply to the generated component class name.fileSuffix
: The suffix to apply to the generated component file name. Defaults to component
.exampleStyles
: Whether to include example styles in the generated component file. Defaults to true
.The following directives are available to import from the ng-primitives/meter
package:
The value of the meter.
The minimum value of the meter.
The maximum value of the meter.
Define a function that returns the meter value label.
[ngpMeter]
ngpMeter
[ngpMeterLabel]
ngpMeterLabel
[ngpMeterValue]
ngpMeterValue
[ngpMeterTrack]
ngpMeterTrack
[ngpMeterIndicator]
ngpMeterIndicator
Adheres to the Meter Accessibility guidelines.
Copyright © 2025 Angular Primitives