Question

i have data like this :

$scope.list = {
  0:{'type':'text','required':true},
  1:{'type':'text','required':false},
  2:{'type':'text','required':true}
};

i'm using ng-repeat to create form

<div ng-repeat="l in list">
  <input type="{{l.type}}" />
</div>

how I want to get the attributes "required" if the value of "l.required" is true

like this :

<div>
  <input type="text" required />
</div>
<div>
  <input type="text" />
</div>
<div>
  <input type="text" required />
</div>

how I do that

Was it helpful?

Solution

Try:

<div ng-repeat="(k, l) in list">
  <input type="{{l.type}}" ng-required="l.required" />
</div>

since it is an object that you are iterating through you would need to use the value of the iteration i.e (k, l) in list and use ng-required to set the required flag.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top