File tree Expand file tree Collapse file tree 3 files changed +10
-13
lines changed Expand file tree Collapse file tree 3 files changed +10
-13
lines changed Original file line number Diff line number Diff line change 66 Directive ,
77 View ,
88 Host ,
9- NgValidator ,
109 forwardRef ,
1110 Binding ,
1211 EventEmitter
Original file line number Diff line number Diff line change 66 Directive ,
77 View ,
88 Host ,
9- NgValidator ,
109 forwardRef ,
1110 Binding
1211} from 'angular2/bootstrap' ;
Original file line number Diff line number Diff line change 66 Directive ,
77 View ,
88 Host ,
9- NgValidator ,
9+ NG_VALIDATORS ,
1010 forwardRef ,
1111 Binding
1212} from 'angular2/bootstrap' ;
@@ -32,20 +32,19 @@ class CheckoutModel {
3232/**
3333 * Custom validator.
3434 */
35+ function creditCardValidator ( c ) : StringMap < string , boolean > {
36+ if ( isPresent ( c . value ) && RegExpWrapper . test ( new RegExp ( "^\\d{16}$" ) , c . value ) ) {
37+ return null ;
38+ } else {
39+ return { "invalidCreditCard" : true } ;
40+ }
41+ }
42+
3543const creditCardValidatorBinding =
36- CONST_EXPR ( new Binding ( NgValidator , { toAlias : forwardRef ( ( ) => CreditCardValidator ) } ) ) ;
44+ CONST_EXPR ( new Binding ( NG_VALIDATORS , { toValue : creditCardValidator , multi : true } ) ) ;
3745
3846@Directive ( { selector : '[credit-card]' , bindings : [ creditCardValidatorBinding ] } )
3947class CreditCardValidator {
40- get validator ( ) { return CreditCardValidator . validate ; }
41-
42- static validate ( c ) : StringMap < string , boolean > {
43- if ( isPresent ( c . value ) && RegExpWrapper . test ( new RegExp ( "^\\d{16}$" ) , c . value ) ) {
44- return null ;
45- } else {
46- return { "invalidCreditCard" : true } ;
47- }
48- }
4948}
5049
5150/**
You can’t perform that action at this time.
0 commit comments