0

I'm trying to update the sections of stores in my user. To do this I think I need the indexOf the array. I can get it in the html, but am having a hard time doing it in the angular controller.

//controller
// How do I get indexOf $scope.global.user.store[?] here instead of in html?
$scope.$watch('radio.model', function() {
  $scope.filteredArray = filterFilter($scope.global.user.store, {});
}, true);

I can select a radio button and it'll tell me the indexOf the store in the Array

<!-- html -->
<div ng-repeat="entry in filteredArray | filter: {name:radio.model.name}">
  {{filteredArray.indexOf(entry)}}
</div>

I need to be able to say, for example, $scope.global.user.store[1].section = $scope.newSectionInput so I can $update. My friend told me there's another way to update an object inside an array using something called the dot rule, if that helps answer this question. How do I get the indexOf inside the js controller? Been working on this for 24+ hours, tried searching all over, can't find the answer to this question.

Update:

<li ng-repeat="store in global.user.store">
  <label ng-model="radio.model" btn-radio="store">
    {{store.name}}
  </label>
</li>

So the idea is it's a section in the store. So I look up the store object which has a name property and section property. And I want to update the store object with different sections.

5
  • You want to get index of what? Index of selected radio? In this case, u need just add ng-model to the radio input. Commented Oct 27, 2014 at 11:52
  • Thanks for your interest/response, Petr. I'm just trying to update an object inside user. So the radio is an ng-repeat of store in global.user.store. I'll edit my original question for you. Commented Oct 27, 2014 at 12:03
  • you will get index of each ng-repeat item in $index, for proper solution please host your code on fiddle.:) Commented Oct 27, 2014 at 12:11
  • This is the fiddle I have so far and the radio buttons won't stay red when I click them? jsfiddle.net/Squ34k3rZ/0zz1zLzL/2 Commented Oct 27, 2014 at 12:44
  • {{filteredArray.indexOf(entry)}} is the wrong approach. You need to use an angular filter for operations such as these Commented Oct 28, 2014 at 8:26

0

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.