Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/20.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 美元手表的替代品_Javascript_Angularjs - Fatal编程技术网

Javascript 美元手表的替代品

Javascript 美元手表的替代品,javascript,angularjs,Javascript,Angularjs,我有一个用正则表达式验证inputvalue的指令。 现在我使用$watch检查输入值是否更改,但由于性能原因,我想尝试另一种方法 scope.$watch(attrs.ngModel, function (inputValue) { formatter(inputValue); }); formatter函数只是通过正则表达式检查inputvalue是否有效,并调用$setValidity() 我尝试使用$parsers,但在更改输入值时发现该值没有直接验证,如下所示: model

我有一个用正则表达式验证inputvalue的指令。 现在我使用$watch检查输入值是否更改,但由于性能原因,我想尝试另一种方法

scope.$watch(attrs.ngModel, function (inputValue) {
     formatter(inputValue);
});
formatter函数只是通过正则表达式检查inputvalue是否有效,并调用$setValidity()

我尝试使用$parsers,但在更改输入值时发现该值没有直接验证,如下所示:

modelCtrl.$parsers.push(formatter);
    if (scope[attrs.ngModel] && scope[attrs.ngModel] !== '') {
        formatter(scope[attrs.ngModel]);
    }
在输入值更改后,是否有任何方法可以立即验证输入

  • 如果您有用于验证的自定义指令,请使用$asyncvalidators
  • ng模式可以在标记后立即用于正则表达式验证

  • 你试过ng模式指令吗?我确实试过,但我使用指令在多个输入上动态使用它