Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/451.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript Can AngularJS“;“价值”;服务持有正则表达式?_Javascript_Angularjs_Angularjs Service - Fatal编程技术网

Javascript Can AngularJS“;“价值”;服务持有正则表达式?

Javascript Can AngularJS“;“价值”;服务持有正则表达式?,javascript,angularjs,angularjs-service,Javascript,Angularjs,Angularjs Service,我创建了一个angularValue服务,它保存一个正则表达式,然后将它附加到控制器实例,即 myService.value('regexValue' {PASSWORD_REGEX: /passwordregex/}) 然后,我尝试在输入字段数据ng模式属性中使用此值 然而,这似乎不适用于ng模式指令 我的问题是如何实现这一点?ng模式需要模式的字符串表示形式(不带/),因此您可以通过访问源属性从正则表达式中获取: <input type="password" data-ng-pa

我创建了一个angular
Value
服务,它保存一个正则表达式,然后将它附加到控制器实例,即

myService.value('regexValue' {PASSWORD_REGEX: /passwordregex/})

然后,我尝试在输入字段
数据ng模式
属性中使用此值

然而,这似乎不适用于ng模式指令


我的问题是如何实现这一点?

ng模式需要模式的字符串表示形式(不带/),因此您可以通过访问
源属性从正则表达式中获取:

<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX.source">

ng模式需要模式的字符串表示形式(不带/),因此您可以通过访问
source
属性从正则表达式中获取该表示形式:

<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX.source">

ng模式需要模式的字符串表示形式(不带/),因此您可以通过访问
source
属性从正则表达式中获取该表示形式:

<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX.source">

ng模式需要模式的字符串表示形式(不带/),因此您可以通过访问
source
属性从正则表达式中获取该表示形式:

<input type="password" data-ng-pattern="myController.regexValue.PASSWORD_REGEX.source">

你的理论是正确的
ng模式
接受模式的字符串表示、内联模式或作用域变量。唯一的问题是,您正在控制器下以controller.regexValue作用域regexValue.PASSWORD\u REGEX,然后尝试访问controller.regexValue.PASSWORD\u REGEX

或者:

myController(regexValue) { 

    this.regexValue = regexValue.PASSWORD_REGEX;  
}

<input type="password" data-ng-pattern="myController.regexValue">
myController(regexValue){
this.regexValue=regexValue.PASSWORD\u REGEX;
}

myController(regexValue){
this.regexValue=regexValue;
}

工作小提琴:你的理论是正确的
ng模式
接受模式的字符串表示、内联模式或作用域变量。唯一的问题是,您正在控制器下以controller.regexValue作用域regexValue.PASSWORD\u REGEX,然后尝试访问controller.regexValue.PASSWORD\u REGEX

或者:

myController(regexValue) { 

    this.regexValue = regexValue.PASSWORD_REGEX;  
}

<input type="password" data-ng-pattern="myController.regexValue">
myController(regexValue){
this.regexValue=regexValue.PASSWORD\u REGEX;
}

myController(regexValue){
this.regexValue=regexValue;
}

工作小提琴:你的理论是正确的
ng模式
接受模式的字符串表示、内联模式或作用域变量。唯一的问题是,您正在控制器下以controller.regexValue作用域regexValue.PASSWORD\u REGEX,然后尝试访问controller.regexValue.PASSWORD\u REGEX

或者:

myController(regexValue) { 

    this.regexValue = regexValue.PASSWORD_REGEX;  
}

<input type="password" data-ng-pattern="myController.regexValue">
myController(regexValue){
this.regexValue=regexValue.PASSWORD\u REGEX;
}

myController(regexValue){
this.regexValue=regexValue;
}

工作小提琴:你的理论是正确的
ng模式
接受模式的字符串表示、内联模式或作用域变量。唯一的问题是,您正在控制器下以controller.regexValue作用域regexValue.PASSWORD\u REGEX,然后尝试访问controller.regexValue.PASSWORD\u REGEX

或者:

myController(regexValue) { 

    this.regexValue = regexValue.PASSWORD_REGEX;  
}

<input type="password" data-ng-pattern="myController.regexValue">
myController(regexValue){
this.regexValue=regexValue.PASSWORD\u REGEX;
}

myController(regexValue){
this.regexValue=regexValue;
}

工作小提琴:

如果你看这个示例,它显示的是
/
,这只适用于angularJS的旧版本,并且已经纠正(1.3之后)。如果你看这个示例,它显示的是
/
,这只适用于angularJS的旧版本,并且已经纠正(1.3之后)如果您查看此示例,其中显示的是
/
,这仅适用于angularJS的较旧版本,并且已经纠正(在1.3之后)。如果您查看此示例,其中显示的是
/
,这仅适用于angularJS的较旧版本,并且已经纠正(在1.3之后)