ng-required无法正常工作

问题描述 投票:0回答:1

我的TextEdit上有一个必须满足的条件。

当我检查谷歌检查屏幕时,我可以看到我的情况正常(Test.Pack.substring(0,2)!='RR')

但是,我看到即使ng-required = false,它仍然在元素上具有required =“required”属性。

我的代码和截图在下面。有什么想法吗?

You can see the required and ng-required in the picture

<!DOCTYPE html>
<html lang="">

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title></title>
</head>

<body>
    <div ng-app="myApp" ng-controller="myCtrl">
    <form name="TestList" id="InsertForm" ng-submit="insert(Test);">

        <div>
            <input ng-model="Test.Pack" >
        </div>
        <div>
            <input ng-model="Test.LM" ng-required="{{Test.Pack.substring(0,2) != 'RR'}}">
        </div>
        <div>
            <button ng-disabled="TestList.$invalid">Test Button</button>
        </div>
    </form>

    </div>
</body>

</html>
<script src="angular.min.js"></script>
<script>
    var app = angular.module('myApp', []);

    //myApp.directive('myDirective', function() {});
    //myApp.factory('myService', function() {});

    app.controller('myCtrl', function($scope) {

    });

</script>
angularjs required ng-required
1个回答
1
投票

传递给ng-required的值应该是boolean.So更改此值

 <div>
                <input ng-model="Test.LM" ng-required="{{Test.Pack.substring(0,2) != 'RR'}}">
    </div>

<div>
            <input ng-model="Test.LM" ng-required="Test.Pack.substring(0,2) != 'RR'">
        </div>
© www.soinside.com 2019 - 2024. All rights reserved.