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

编程入门 行业动态 更新时间:2024-10-07 17:24:06
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.

更多推荐

本文发布于:2023-08-07 17:29:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1465268.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   控制台   错误   Dart   error

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!