0

i have this code:

angular.module('ExampleApp', ['ngDraggable']).
      controller('MainCtrl', function ($scope) {
        $scope.centerAnchor = true;
        $scope.toggleCenterAnchor = function () {$scope.centerAnchor = !$scope.centerAnchor}
        $scope.draggableObjects = [{name:'subject1'}, {name:'subject2'}, {name:'subject3'}];
        $scope.droppedObjects1 = [];
        $scope.droppedObjects2 = [];
        $scope.onDropComplete1=function(data,evt,i){
            var index = $scope.droppedObjects1.indexOf(data);
            if (index == -1)
            $scope.droppedObjects1.push(data);
        }
        $scope.onDragSuccess1=function(data,evt){
            console.log("133","$scope","onDragSuccess1", "", evt);
            var index = $scope.droppedObjects1.indexOf(data);
            if (index > -1) {
                $scope.droppedObjects1.splice(index, 1);
            }
        }
        var inArray = function(array, obj) {
            var index = array.indexOf(obj);
        }
      });

and variable "i" pass in function call and i want to do like this var index = $scope.droppedObjects+i.indexOf(data); how this is possible?

2 Answers 2

2

You can try

var index = $scope["droppedObjects"+i].indexOf(data);
Sign up to request clarification or add additional context in comments.

Comments

0

Can you try using This Concept. I Hope Help you some portion.

var i=0;
var the_string = 'droppedObjects' + i;

// Get the model //
var model = $parse(the_string);

// Assigns a value to it //
model.assign($scope, 42);

console.log($scope.droppedObjects0);

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.