Home > Software design >  Assign a property to a variable in ng-repeat
Assign a property to a variable in ng-repeat

Time:09-08

How can I assign a property (in this case status.val) to a variable in ng-repeat so that I can apply translation to it like the one used above translation.status?

<div>
  <label for="status">{{translation.status}}</label>
  <select  id="status" ng-model="extraItemForm.status" ng-required="true">
    <option ng-repeat="status in statusList" value="{{status.id}}">
      {{status.val}}
    </option>
  </select>
</div>

CodePudding user response:

You can use ng-init

html

<div ng-controller="MainCtrl">
    <ul>
        <li ng-repeat="mentor in mentors" ng-init="test = mentor">{{test}}</li>
    </ul>
</div>

js

var app = angular.module('myApp', []);

function MainCtrl( $scope ) {
    $scope.mentors = [ 'Jonathan', 'Nathan', 'Chris', 'Brian', 'Timothy' ];
}

jsfiddle

CodePudding user response:

You can use ng-options inside select and add translate. [enter link description here][1]

[1]: https://plnkr.co/edit/ViSF2DWK1amSW8BwwPKn?p=preview&preview <select ng-model="me.gender" ng-options="gender.name | translate for gender in genders"></select>

  • Related