npm install ng-brazil-imask
Contains pipes / directives / validators / mask for brazillian like apps
Supports: Angular2 to Angular17
This is a WIP project based on NgBrazil
Modules:
* CPF
* CNPJ
* RG
* Telefone e Celular
* CEP
* Currency (Dinheiro)
To install this library with npm, run:
npm install --save ng-brazil-imask
Import module in root
``ts
import { NgBrazil } from 'ng-brazil'
@NgModule({
declarations: [
AppComponent
],
imports: [
....,
NgBrazil
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
``
Then setup your component:ts
import { Component } from '@angular/core';
import { MASKS, NgBrazilValidators } from 'ng-brazil';
@Component({
selector: 'app-root',
template: '',
styleUrls: ['./app.component.css']
})
export class AppComponent {
public MASKS = MASKS;
constructor() {
this.formFields = {
estado: [''],
cpf: ['', [
cnpj: ['', [
rg: ['', [
cep: ['', [
telefone: ['', [
inscricaoestadual: ['', [
};
this.form = this.fb.group(this.formFields);
}
}
`
`html`
`html
CPF: From 12345678910 to {{'12345678910' | cpf}}
CNPJ: From 40841253000102 to {{'40841253000102' | cnpj}}
Telefone: From 3199998888 to {{'3199998888' | telefone}}
Number: From 123.23 to {{'123.23' | numberBrazil}}
Number sem decimais: From 123.23 to {{'123.23' | numberBrazil: 0}}
Currency: From 123.23 to {{'123.23' | currencyBrazil}}
`
`ts
import { Component } from '@angular/core';
import { NgBrDirectives } from 'ng-brazil';
@Component({
selector: 'app-root',
template: '',
styleUrls: ['./app.component.css']
})
export class AppComponent {
inscricaoestadual() {
const {InscricaoEstadualPipe} = NgBrDirectives;
return new InscricaoEstadualPipe()
.transform('625085487072', 'sp');
}
}
`
Run ng serve for a dev server. Navigate to http://localhost:4200/. The application will automatically reload if you change any of the source files.
Run ng generate component component-name to generate a new component. You can also use ng generate directive|pipe|service|class|guard|interface|enum|module.
Run ng build to build the project. The build artifacts will be stored in the dist/ directory.
Run ng test to execute the unit tests via Karma.
Run ng e2e to execute the end-to-end tests via a platform of your choice. To use this command, you need to first add a package that implements end-to-end testing capabilities.
To get more help on the Angular CLI use ng help` or go check out the Angular CLI Overview and Command Reference page.