0

I have ng-click event:

removeFile(file, $index);

Where file is object:

File
$$hashKey:"object:572"
lastModified:1487594253749
lastModifiedDate:Mon Feb 20 2017 15:37:33 GMT+0300 (RTZ 2 (зима))
name:"1 — копия — копия — копия.jpg"
size:315074
type:"image/jpeg"
webkitRelativePath:""

I try to remove object mentioned above from array Files:

I tried:

delete $scope.files[index];
2

3 Answers 3

1

You can use splice :

$scope.removeFile = function(file){
    var index = $scope.files.indexOf(file);
    $scope.files.splice(index,1);
}
Sign up to request clarification or add additional context in comments.

Comments

0

In place of delete use splice

var index = $scope.files.indexOf(index);
  if(index>=0)
    $scope.files.splice(index, 1);
}

Comments

0

best way to do this using filter function of array

$scope.removeFile = function(file){
    $scope.files = $scope.files.filter(function(fileItem) {
        return fileItem.name != file.name;
    });
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.