ng-required doesn't work properly

111 Views Asked by At

I have an ng-required condition on my TextEdit.

When I check the google inspection screen, I can see that my condition works properly (Test.Pack.substring(0,2) != 'RR')

However, I see that even though ng-required = false, it is still has a required = "required" property on the element.

my code and screenshot in below. Is there any idea about this?

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>
1

There are 1 best solutions below

0
On BEST ANSWER

The value passed to ng-required should be boolean.So change this

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

to

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