1

When I do the following in my code

<pre>{{uploader.queue.indexOf(item)|json}}</pre>

I get an index of the element that I am looking for but if I do something like this

removeAllFiles(uploader.queue.indexOf(item))

The result is always

-1

7
  • Are you sure uploader.queue.indexOf(uploader.queue.indexOf(item)) is what you want to do? The inner function returns an index and you look for that index in the same array. Commented Apr 11, 2014 at 14:02
  • Good catch, just pasted it wrong sorry, always get confused by SO editor. Commented Apr 11, 2014 at 14:03
  • Can you post more of your code? If your remove call is in a controller you need to use $scope.uploader. Commented Apr 11, 2014 at 14:08
  • @eugenekgn Take a look at my answer...... Commented Apr 11, 2014 at 14:14
  • @eugenekgn is that your requirement Commented Apr 11, 2014 at 14:48

1 Answer 1

1

Try this out

Working Demo

html

<div class="container" ng-app="main" ng-controller="Controller">
<div ng-repeat="uploader in uploaders">
      <button ng-click="removeAllFiles(uploader.queue.indexOf(item))">{{uploader.queue.indexOf(item)|json}}
      </button> 
</div>
</div>

script

angular.module('main', []);
// Main Controller
function Controller($scope) {
    $scope.item = 'N'; 
    $scope.uploaders = [{
        clickable: true,
        id:1,
        queue: "ABC-Name"
    }, {
        clickable: false,
        id:2,
        queue: "XYZ-Name"
    }, {
        clickable: true,
        id:3,
        queue: "LMN-Name"
    }];

    $scope.removeAllFiles = function(item) {
     console.log(item);
    }
}
Sign up to request clarification or add additional context in comments.

Comments

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.