Search code examples
javascriptangularjsselectng-options

Syntax Error: Token 'for' is an unexpected token


I'm kinda new to AngularJS, and i'm reading documentations to build a select input using the ng-options directive

https://docs.angularjs.org/api/ng/directive/ngOptions

my code:

$scope.searchFilterDispatcher.distributionCode = [{
      id: 1,
      label: 'dist1'
    }, {
      id: 2,
      label: 'dist2'
    }];
<select ng-model="searchFilterDispatcher.distributionCode"
    ng-options="item as item.label for item in searchFilterDispatcher.distributionCode| translate | uppercase for item in distributionCode"
    class="form-control" id="distributionCode">
    <option value="">{{'SELECT_A_VALUE' | translate}}</option>
</select>

But when I launch the app the following error rise up:

"angular.js:12783 Error: [$parse:syntax] Syntax Error: Token 'for' is an unexpected token "

where do I get wrong?


Solution

  • Possible Solutions 1. Do not mix translate filter with ng-options. try using it seperately 2. uppercase filter should not be on direct ng-option

    Try using This

    ng-options="item as (item.label | upper) for item in searchFilterDispatcher.distributionCode"
    

    Thanks