Search code examples
angularjsdata-bindingbindingangular-ngmodel

concatenate expression with string in ng-model directive


i have the below ng-repeat

<span ng-repeat = "x in levels">
    <input id="{{x}}" type="checkbox" ng-model="Filter.level.{{x}}" ng-true-value="{{x}}"  data-ng-false-value=""/><label for="{{x}}">{{x}}</label>
</span>

im facing issue with the value of ng-model directive

i tried to use it many ways but it didnt work:

ng-model="Filter.level.{{x}}" 

or

ng-model="'Filter.level.'+{{x}}" 

or

ng-model="'Filter.level.'+'{{x}}'" 

or

ng-model="'Filter.level.level'+{{$index}}"

its work only when i use it like ng-model="Filter.level.level1"

but i need the value to be dynamic from ng-repeat like Filter.level.level1, Filter.level.level2 ...


Solution

  • You should access object by index there with the help of [], you can't use {{}}(interpolation directive) inside ng-model

    ng-model="Filter.level[x]"