0

我的 TextEdit 上有一个 ng-required 条件。

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

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

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

可以看到图中的required和ng-required

<!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>
4

1 回答 1

1

传递给 ng-required 的值应该是布尔值。所以改变这个

 <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>
于 2018-03-01T04:16:09.957 回答