Angular2-6,正则表达式和输入装饰器

时间:2018-08-01 07:16:38

标签: regex angular6

我有一个组件,该组件具有input { http_poller { urls => { test1 => { # Supports all options supported by ruby's Manticore HTTP client method => get url => "http://url/metrics/currentUser/metrics" headers => { Accept => "application/json" } } } request_timeout => 29 schedule => { cron => "* * * * * UTC"} codec => "json" } } filter { json { source => "timers" target => "timers" } } output { elasticsearch { hosts => ["localhost:9200"] index => "final" } stdout { } } 装饰器。因此,我正在尝试在其中设置正则表达式。 像

@input()

<component [regex]="/^\d+$/" ></component>

但这没用

1 个答案:

答案 0 :(得分:0)

您可以将RegEx作为字符串值传递,例如

<component [regex]="'^\d+$'"></component>

<component regex="^\d+$"></component>

然后在组件中,您可以使用new RegExp(this.regex);创建实际的正则表达式对象