【发布时间】:2018-10-27 00:06:33
【问题描述】:
我已经根据本教程为模板驱动的表单构建了一个自定义密码验证器:https://juristr.com/blog/2016/11/ng2-template-driven-form-validators/#building-a-custom-validator
但是,我想在应用程序不同部分的多个表单上使用它。我不断收到错误:
Type PasswordValidator is part of the declarations of 2 modules:
SignupModule and AuthModule! Please consider moving PasswordValidator to a higher module that imports SignupModule and AuthModule.
如果我按照它的建议将验证器添加到更高的模块,它就不再起作用了。验证器永远不会到达。好像需要在直接持有表单的模块中导入才有效。
有什么想法吗?
【问题讨论】:
-
只需从两者中删除
PasswordValidator,即SignupModule and AuthModule,而是将其添加到根模块中,以便您可以在整个应用程序中使用它 -
或者为什么不创建一个SharedModule 将这个验证器导出到任何导入这个 SharedModule 的模块?
-
^我尝试了这两种方法,这就是我所说的“如果我按照它的建议将验证器添加到更高的模块”
标签: angular typescript angular-material2