Git Product home page Git Product logo

ng2-cpf-cnpj's Introduction

ng2-cpf-cnpj

Angular directive to validate CPF/CNPJ numbers, using cpf_cnpj.js.

How to install

To install this library, run:

$ npm install ng2-cpf-cnpj --save

How to use

$ npm install ng2-cpf-cnpj

and add to your app.module.ts:

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppComponent } from './app.component';

import { CpfCnpjModule } from 'ng2-cpf-cnpj';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    BrowserModule,
    CpfCnpjModule
  ],
  providers: [],
  bootstrap: [AppComponent]
})
export class AppModule { }

Just add [cpf] or [cnpj] in your inputs:

<input type="text" name="cpf" [(ngModel)]="cpf" [cpf]="cpf"/>
<input type="text" name="cnpj" [(ngModel)]="cnpj" [cnpj]="cnpj" />

You can use reference to detect the error type:

<input type="text" name="cpf" [(ngModel)]="cpf" [cpf]="cpf" #cpfInput="ngModel" required />
<div *ngIf="cpfInput?.errors?.cpf">CPF Invalid</div>
<div *ngIf="cpfInput?.errors?.required">CPF Required</div>

Development

To generate all *.js, *.d.ts and *.metadata.json files:

$ npm run build

To lint all *.ts files:

$ npm run lint

License

MIT © Paulo Menezes

ng2-cpf-cnpj's People

Contributors

paulomenezes avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

ng2-cpf-cnpj's Issues

como ficaria um exemplo usando formControlName?

pensei em algo do tipo..

<input type="text" class="form-control" id="cpf" formControlName="cpf" [cpf]="cpf" mask="000.000.000-00">

                      <div *ngIf="formulario.get('cpf').value?.errors?.cpf" class="form-control-feedback">CPF Inválido</div>

você tem algum exemplo?

Erro ao instalar ng2-cpf-cnpj com npm install

Quando faço npm install ng2-cpf-cnpj --save a versão 0.0.1 é instalada, e nesta versão, ao fazer npm run build, ocorre um erro de dependencia.

Sugestão: Quando fazer npm install ng2-cpf-cnpj --save instalar a ultima versão da biblioteca

Erro após a versão angular 9, incompatibilidade com o Angular Ivy

Na versão 0.1.1, ao realizar npm run build ou ng serve, ocorre o seguinte erro de incompatibilidade com o Angular Ivy

image

Obs: Se desabilitar o Angular ivy a biblioteca funciona, mas esse não é o comportamento desejado, pois o Angular Ivy traz melhorias diversas e possivelmente será obrigatório em futuras versões.

Passos para reproduzir:
1- ng new myapp
2- npm i -s [email protected]
3- Editar o arquivo src\app\app.module.ts e colocar o ng2-cpf-cnpj:

image

4- npm run build

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.