請看看plunker。angularJS ng模式不工作
http://plnkr.co/edit/DuTFYbLVbPkCIvRznYjG?p=preview
,其中n模式正則表達式是不會運用在輸入文本字段。
只要求驗證正確應用。
HTML:
<body ng-controller="tableController">
<form name="test">
<div ng-repeat="model in models">
<span ng-bind="model.caption"></span>
<div ng-form name="frm{{$index}}">
<input name="input{{$index}}"
ng-model="data[model.name]"
ng-disabled="model.isDisabled"
minlength="{{model.minlength}}"
maxlength="{{model.maxlength}}"
ng-show="model.isShow"
ng-pattern="model.pattern"
ng-required="true" />
<br />
{{data[model.name]}}
</div>
</div>
</form>
<br />
<br />
</body>
JS:
angular.module("app", []).controller("tableController", function ($scope) {
$scope.regEx = "/^\\d+$/";
$scope.data = {};
$scope.data.one = 234;
$scope.data.two = 32432;
$scope.models = [
{ name: "one", caption: "cOne", isDisabled: false, isShow: true, minlength: 2, maxlength: 10, pattern: "/^\d+$/" },
{ name: "two", caption: "cTwo", isDisabled: false, isShow: true, minlength: 2, maxlength: 5, pattern: "/^\d+$/" },
];
});
任何建議??
-Thanks
模式預計是JavaScript正則表達式,而不是字符串。 –
當您在SO問題中遇到問題時,將部分代碼與Plunkr一起發佈。 – Sai