@@ -24,14 +24,16 @@ Or run locally:
2424# Usage
2525
2626## Installation
27+
2728``` shell
2829npm install angular-cc-library --save
2930```
3031
3132## Version Compatibility
3233
3334| Angular | Library |
34- | ---------| ---------|
35+ | ------- | ------- |
36+ | 19.x | 3.5.x |
3537| 18.x | 3.4.x |
3638| 17.x | 3.3.x |
3739| 16.x | 3.2.x |
@@ -40,92 +42,103 @@ npm install angular-cc-library --save
4042| 13.x | 3.0.0 |
4143| 12.x | 2.1.3 |
4244
43-
4445## Formatting Directive
46+
4547On the input fields, add the specific directive to format inputs.
4648All fields must be ` type='tel' ` in order to support spacing and additional characters.
4749
48- Since ` angular-cc-library@3.3.0 ` all directives declared as standalone,
50+ Since ` angular-cc-library@3.3.0 ` all directives declared as standalone,
4951so you can import them directly into your component:
5052
5153``` typescript
52- import { Component } from ' @angular/core' ;
53- import { CreditCardFormatDirective } from ' angular-cc-library' ;
54+ import { Component } from " @angular/core" ;
55+ import { CreditCardFormatDirective } from " angular-cc-library" ;
5456
5557@Component ({
56- selector: ' credit-card-number-input' ,
58+ selector: " credit-card-number-input" ,
5759 standalone: true ,
5860 deps: [CreditCardFormatDirective ],
59- template: ` <input id="cc-number" type="tel" autocomplete="cc-number" ccNumber> `
61+ template: ` <input
62+ id="cc-number"
63+ type="tel"
64+ autocomplete="cc-number"
65+ ccNumber
66+ /> ` ,
6067})
6168export class CreditCardNumberInputComponent {}
6269```
6370
6471But you can still import them all at once using ` CreditCardDirectivesModule ` :
6572
6673``` typescript
67- import { NgModule } from ' @angular/core' ;
68- import { BrowserModule } from ' @angular/platform-browser' ;
69- import { FormsModule } from ' @angular/forms' ;
70- import { CreditCardDirectivesModule } from ' angular-cc-library' ;
74+ import { NgModule } from " @angular/core" ;
75+ import { BrowserModule } from " @angular/platform-browser" ;
76+ import { FormsModule } from " @angular/forms" ;
77+ import { CreditCardDirectivesModule } from " angular-cc-library" ;
7178
72- import { AppComponent } from ' ./app.component' ;
79+ import { AppComponent } from " ./app.component" ;
7380
7481@NgModule ({
75- imports: [BrowserModule , FormsModule , CreditCardDirectivesModule ],
76- declarations: [AppComponent ],
77- bootstrap: [AppComponent ]
82+ imports: [BrowserModule , FormsModule , CreditCardDirectivesModule ],
83+ declarations: [AppComponent ],
84+ bootstrap: [AppComponent ],
7885})
79- export class AppModule {
80- }
86+ export class AppModule {}
8187```
8288
8389** Credit Card Formatter**
84- * add ` ccNumber ` directive:
90+
91+ - add ` ccNumber ` directive:
92+
8593``` html
86- <input id =" cc-number" type =" tel" autocomplete =" cc-number" ccNumber >
94+ <input id =" cc-number" type =" tel" autocomplete =" cc-number" ccNumber / >
8795```
88- * this will also apply a class name based off the card ` .visa ` , ` .amex ` , etc. See the array of card types in ` credit-card.ts ` for all available types
8996
90- * You can get parsed card type by using export api:
97+ - this will also apply a class name based off the card ` .visa ` , ` .amex ` , etc. See the array of card types in ` credit-card.ts ` for all available types
98+
99+ - You can get parsed card type by using export api:
91100
92101``` html
93- <input type =" tel" ccNumber #ccNumber =" ccNumber" >
102+ <input type =" tel" ccNumber #ccNumber =" ccNumber" / >
94103<span class =" scheme" >{{ccNumber.resolvedScheme$ | async}}</span >
95104```
96105
97106` resolvedScheme$ ` will be populated with ` visa ` , ` amex ` , etc.
98107
99-
100108** Expiration Date Formatter**
101109Will support format of MM/YY or MM/YYYY
102- * add ` ccExp ` directive:
110+
111+ - add ` ccExp ` directive:
112+
103113``` html
104- <input id =" cc-exp-date" type =" tel" autocomplete =" cc-exp" ccExp >
114+ <input id =" cc-exp-date" type =" tel" autocomplete =" cc-exp" ccExp / >
105115```
106116
107117** CVC Formater**
108- * add ` ccCVC ` directive:
118+
119+ - add ` ccCVC ` directive:
120+
109121``` html
110- <input id =" cc-cvc" type =" tel" autocomplete =" off" ccCVC >
122+ <input id =" cc-cvc" type =" tel" autocomplete =" off" ccCVC / >
111123```
112124
113125### Validation
126+
114127Current only Model Validation is supported.
115128To implement, import the validator library and apply the specific validator on each form control
116129
117130``` typescript
118- import { CreditCardValidators } from ' angular-cc-library' ;
131+ import { CreditCardValidators } from " angular-cc-library" ;
119132
120133@Component ({
121- selector: ' app' ,
134+ selector: " app" ,
122135 template: `
123136 <form #demoForm="ngForm" (ngSubmit)="onSubmit(demoForm)" novalidate>
124137 <input id="cc-number" formControlName="creditCard" type="tel" autocomplete="cc-number" ccNumber>
125138 <input id="cc-exp-date" formControlName="expirationDate" type="tel" autocomplete="cc-exp" ccExp>
126139 <input id="cc-cvc" formControlName="cvc" type="tel" autocomplete="off" ccCVC>
127140 </form>
128- `
141+ ` ,
129142})
130143export class AppComponent implements OnInit {
131144 form: FormGroup ;
@@ -135,9 +148,12 @@ export class AppComponent implements OnInit {
135148
136149 ngOnInit() {
137150 this .form = this ._fb .group ({
138- creditCard: [' ' , [CreditCardValidators .validateCCNumber ]],
139- expirationDate: [' ' , [CreditCardValidators .validateExpDate ]],
140- cvc: [' ' , [Validators .required , Validators .minLength (3 ), Validators .maxLength (4 )]]
151+ creditCard: [" " , [CreditCardValidators .validateCCNumber ]],
152+ expirationDate: [" " , [CreditCardValidators .validateExpDate ]],
153+ cvc: [
154+ " " ,
155+ [Validators .required , Validators .minLength (3 ), Validators .maxLength (4 )],
156+ ],
141157 });
142158 }
143159
0 commit comments