angular - 如何将数组发送到角度自定义验证器
问题描述
这是我的验证器功能。我需要从我的组件传递条形码数组。我尝试了很多方法,但没有任何效果。
checkBarcodes(control: AbstractControl): { [key: string]: boolean } | null {
let barcodes = ["6456", "6545", "2", "2", "121", "22", "11111", "22222"]
for (let code of barcodes) {
if (code == control.value) {
return {
isValid: true
}
}
}
return null
}
解决方案
export function checkBarcodes(barcodes): ValidatorFn {
return (control : AbstractControl) : ({ [key: string]: boolean } | null) => {
for (let code of barcodes) {
if (code === control.value) {
return null ;
}
}
return {'codeInvalid': true} ;
}
}
推荐阅读
- r - 使用不同变量的额外条件在每个组中查找最大日期。得到一个错误 Max()& not defined for Date 对象
- javascript - Vue.js - 更新和渲染数组的性能成本
- python-3.x - Pandas groupby 计算未来 n 天的滚动总和
- java - 如何为特定进程指定线程池
- windows-task-scheduler - Windows 7 任务计划程序 - 在“无论用户是否登录都运行”模式下不工作
- rest - 我可以使用 PUT http 方法来检索数据而不是使用 GET
- javascript - 如何注册唯一值?在电子表格谷歌应用脚本网络中
- excel - Vba 抓取 Twitter 详细信息
- artifactory - 有没有办法只备份工件存储库的元数据而不是内容
- javascript - Javascript - 返回初始状态