我有一个组件,它有@input()
装饰器。所以,我正在尝试在其中设置正则表达式。就像是
<component [regex]="/^\d+$/" ></component>
或者
<component [regex]="new RegExp('ab+c')" ></component>
但它没有用
您可以将 RegEx 作为字符串值传递,例如
<component [regex]="'^\d+$'"></component>
或者
<component regex="^\d+$"></component>
然后在您的组件中,您可以new RegExp(this.regex);
用来创建实际的正则表达式对象
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句