eugenekgn
eugenekgn

Reputation: 1722

AngularJS binding issues

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

Upvotes: 1

Views: 55

Answers (1)

Nidhish Krishnan
Nidhish Krishnan

Reputation: 20741

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);
    }
}

Upvotes: 1

Related Questions