Dart中的自定义angular2验证器给出控制台错误(Custom angular2 validator in Dart giving console error)

我试图使用Dart制作angular2验证器:

。镖

class CustomValidators { static Map<String, bool> wordValidator(Control ctrl) { if( matches(ctrl.value, r"^[A-Za-z]{1,}[\'\ \,\.\-]*[a-z]*$")) { return {'wordValidator': true}; } } }

其中匹配具有以下定义:

火柴

/// check if string matches the pattern. bool matches(String str, pattern) { RegExp re = new RegExp(pattern); return re.hasMatch(str); }

当我尝试运行验证时,我在控制台中获得以下内容

控制台输出

(anonymous function) ERROR CONTEXT: (anonymous function) DartObject (anonymous function) < Uncaught Unhandled exception: EXCEPTION: Invalid argument(s) in [AST] ORIGINAL EXCEPTION: Invalid argument(s) ORIGINAL STACKTRACE: #0 _JSSyntaxRegExp.hasMatch (dart:core-patch/regexp_patch.dart:174) #1 matches (package:validator/src/validator.dart:53:13) #2 CustomValidators.wordValidator (package:epimss_ng2_shared/validators.dart:83:9) ...

(package:epimss_ng2_shared/validators.dart:83:9)指向上面的匹配方法。

谢谢

I am attempting to make an angular2 validator using Dart:

.dart

class CustomValidators { static Map<String, bool> wordValidator(Control ctrl) { if( matches(ctrl.value, r"^[A-Za-z]{1,}[\'\ \,\.\-]*[a-z]*$")) { return {'wordValidator': true}; } } }

where matches has the following definition:

matches

/// check if string matches the pattern. bool matches(String str, pattern) { RegExp re = new RegExp(pattern); return re.hasMatch(str); }

When I attempt to run the validation I get the following in the console

console ouput

(anonymous function) ERROR CONTEXT: (anonymous function) DartObject (anonymous function) < Uncaught Unhandled exception: EXCEPTION: Invalid argument(s) in [AST] ORIGINAL EXCEPTION: Invalid argument(s) ORIGINAL STACKTRACE: #0 _JSSyntaxRegExp.hasMatch (dart:core-patch/regexp_patch.dart:174) #1 matches (package:validator/src/validator.dart:53:13) #2 CustomValidators.wordValidator (package:epimss_ng2_shared/validators.dart:83:9) ...

(package:epimss_ng2_shared/validators.dart:83:9) points to the matches method above.

Thanks

最满意答案

没有完整的回购案件很​​难说。

我假设ctrl.value返回null或一些其他非String值。

Hard to tell without a full repo case.

I assume ctrl.value returns null or some other non-String value.

Dart中的自定义angular2验证器给出控制台错误(Custom angular2 validator in Dart giving console error)

我试图使用Dart制作angular2验证器:

。镖

class CustomValidators { static Map<String, bool> wordValidator(Control ctrl) { if( matches(ctrl.value, r"^[A-Za-z]{1,}[\'\ \,\.\-]*[a-z]*$")) { return {'wordValidator': true}; } } }

其中匹配具有以下定义:

火柴

/// check if string matches the pattern. bool matches(String str, pattern) { RegExp re = new RegExp(pattern); return re.hasMatch(str); }

当我尝试运行验证时,我在控制台中获得以下内容

控制台输出

(anonymous function) ERROR CONTEXT: (anonymous function) DartObject (anonymous function) < Uncaught Unhandled exception: EXCEPTION: Invalid argument(s) in [AST] ORIGINAL EXCEPTION: Invalid argument(s) ORIGINAL STACKTRACE: #0 _JSSyntaxRegExp.hasMatch (dart:core-patch/regexp_patch.dart:174) #1 matches (package:validator/src/validator.dart:53:13) #2 CustomValidators.wordValidator (package:epimss_ng2_shared/validators.dart:83:9) ...

(package:epimss_ng2_shared/validators.dart:83:9)指向上面的匹配方法。

谢谢

I am attempting to make an angular2 validator using Dart:

.dart

class CustomValidators { static Map<String, bool> wordValidator(Control ctrl) { if( matches(ctrl.value, r"^[A-Za-z]{1,}[\'\ \,\.\-]*[a-z]*$")) { return {'wordValidator': true}; } } }

where matches has the following definition:

matches

/// check if string matches the pattern. bool matches(String str, pattern) { RegExp re = new RegExp(pattern); return re.hasMatch(str); }

When I attempt to run the validation I get the following in the console

console ouput

(anonymous function) ERROR CONTEXT: (anonymous function) DartObject (anonymous function) < Uncaught Unhandled exception: EXCEPTION: Invalid argument(s) in [AST] ORIGINAL EXCEPTION: Invalid argument(s) ORIGINAL STACKTRACE: #0 _JSSyntaxRegExp.hasMatch (dart:core-patch/regexp_patch.dart:174) #1 matches (package:validator/src/validator.dart:53:13) #2 CustomValidators.wordValidator (package:epimss_ng2_shared/validators.dart:83:9) ...

(package:epimss_ng2_shared/validators.dart:83:9) points to the matches method above.

Thanks

最满意答案

没有完整的回购案件很​​难说。

我假设ctrl.value返回null或一些其他非String值。

Hard to tell without a full repo case.

I assume ctrl.value returns null or some other non-String value.