WebTechKitchen; Your Web Technology Kitchen, contact us to create, or maintain your websites and other digital properties.

ng-options sorted by key, and displaying the value from an associative array

Submitted by barnettech on Wed, 01/13/2016 - 15:44

ng-options sorted by key, and displaying the value from an associative array

 

$scope.itemsBreakInCoverage = [{key:'1', value:'1 year'}, {key:'2', value:'2 years'}, {key:'3', value:'3 years'},
    {key:'4', value:'4 years'}, {key:'5', value:'5 years'}, {key:'6', value:'6 years'}, {key:'7', value:'7 years'},
    {key:'8', value:'8 years'}, {key:'9', value:'9 years'}, {key:'10', value:'10 years'}, {key:'11', value:'11 years'},
    {key:'12', value:'12 years'}, {key:'13', value:'13 years'}, {key:'14', value:'14 years'}, {key:'15', value:'15 years'},
    {key:'More than 15', value:'More than 15'}];

 

<p ng-show="formData.hasCarInsurance=='yes'" id="no-break-coverage">HOW LONG WITHOUT A BREAK IN COVERAGE?<br>
    <select ng-model="formData.no_break_coverage1" name="no_break_coverage1" ng-options="item as item.value for item in itemsBreakInCoverage track by item.key" ng-required="formData.hasCarInsurance=='yes'">
        <option></option>
    </select>
</p>