1

i have to following issue. I have an nested ng-repeat with two radio-buttons, when i select an radion-button the value is set correctly to the model. But when i filter to a value that's not in the collection the value is not set to the view (the model is still correct)

to reproduce:

Example

when you check all 3 radio-buttons to lets say 'read', than type 'x' into the input to filter, now remove the value from the input. the last radio is selected the others are not.

ps. i've tryed ng-value instead of value.

controller:

vm.list = [{id: 1, name: 'Item1', items: [{id: 1, name: 'SubItem1.1'}, {id: 2, name: 'SubItem1.2'}, {id: 3, name: 'SubItem1.3'}]}]

view:

<input type="text" ng-model="search" /> 
<ul>
 <li ng-repeat="item in vm.list">
   <h4 ng-bind="item.name"></h4>
   <ul>
     <li ng-repeat="subitem in item.items | filter:search">
       <h4 ng-bind="subitem.name"></h4>

       <input type="radio" name="{{item.id}}{{subitem.id}}" ng-model="subitem.permission" value="read" /> Read
       <input type="radio" name="{{item.id}}{{subitem.id}}" ng-model="subitem.permission" value="write" /> Write
     </li>
   </ul>
 </li>

1 Answer 1

1

change the input name from

name="{{item.id}}{{subitem.id}}"

to

name="{{subitem.id}}"
Sign up to request clarification or add additional context in comments.

4 Comments

this works! thank you!!! but why is this name="{{item.id}}{{subitem.id}}" not working?
i didn't find the reason. i don't know why your input name didn't work
I suspect it's down to scoping. Each repeat creates a new scope. To be honest, it looks like a bug in Angular model binding itself to me.
if you dont have an unique key in subitem you also can use {{item.id + subitem.id }} this works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.