gpt4 book ai didi

angularjs - angularJS ng模式不起作用

转载 作者:行者123 更新时间:2023-12-04 13:39:38 29 4
gpt4 key购买 nike

请看看朋克。

http://plnkr.co/edit/DuTFYbLVbPkCIvRznYjG?p=preview

ng-pattern regEx不适用于输入文本字段。

仅在需要验证的情况下才能正确应用。

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+$/" },
];
});

有什么建议吗??

-谢谢

最佳答案

将正则表达式分配更改为以下内容。由于它应该是一个正则表达式。如果您用双引号引起来,那么它将变成一个字符串。

$scope.regEx = /^\d+$/;

关于angularjs - angularJS ng模式不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22612453/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com