AngularJS ng-pattern失效问题?

sdApp.directive("sdVerNumber", function(){
    return{
        restrict: "A",
        replace: true,
        template: "<input type=\"text\" ng-pattern=\"/^([1-9]+[0-9]*|[0])([.]+[0-9]{0,2}|[.])?$/\" />"
    };
});
<input type="text" sd-ver-number class="sd-input-text sd-input-small" style="width:80px;" ng-model="addListData.m1" />

当输入内容错误的时候,对应状态的类ng-invalid-pattern没有相应改变。而直接把整个ng-pattern写在HTML上是可以正常工作的。请问这是为什么呢?


MYYA
浏览 1705回答 1
1回答

四季花海

sdApp.directive("sdVerNumber", function(){&nbsp; &nbsp; return{&nbsp; &nbsp; &nbsp; &nbsp; restrict: "A",&nbsp; &nbsp; &nbsp; &nbsp; replace: true,&nbsp; &nbsp; &nbsp; &nbsp; template: "<input type=\"text\" ng-pattern=\"^([1-9]+[0-9]*|[0])([.]+[0-9]{0,2}|[.])?$\" />"&nbsp; &nbsp; };});<input type="text" sd-ver-number class="sd-input-text sd-input-small" style="width:80px;" ng-model="addListData.m1" />
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript