AngularJS ng-required does not work with variables


I have to use the directive ng-required, but I cannot hardcode true or false. I need to use it in a variable, but angular does not recognize the "true".

jsFiddle example

<div ng-app ng-init="test=true">
        both have ng-required="true"
        one as hardcoded string literal, one via a variable
        Inspect them, one is not required!
    <form name="myForm">
        <input type="text" ng-required="{{test}}" />
        <input type="text" ng-required="true" />

How can I get this working?

<input type="text" ng-required="{{test}}" />

You don't need to interpolate test here. Since you want to evaluate the value of test, just remove the curly braces and it should work.