0

I have api call on $on i got the Json response that is attached with the question. i was able to display fileName in the li , Now i have delete function when user click on remove icon i am calling function and trying to get rskAsesAprvAtchKy key so i can post the key to backend to delete this file.

It is coming undefined i am not sure what i am missing any help will be appreciated..

main.html

<div class="row">
    <div class="col-md-6">
        <ul>
            <li ng - repeat="file in attachedDoc">{{file . fileName}}
                <a href="" ng - click="deleteFile()">
                    <span class="glyph_remove"></span>
                </a>
            </li>
        </ul>
    </div>
</div>

factory.js

$scope.$on('addEditAttest', function (s, attestorObj) {
    $scope.attestorObj = attestorObj;
    attestorFactory.getAttachedDocument($scope.attestorObj.riskAssessmentRoleAsgnKey)
        .then(function (response) {
            $scope.attachedDoc = response.data;
        });
});

$scope.deleteFile = function () {
    var fileKey;
    $scope.attachedDoc.rskAsesAprvAtchKy = fileKey;
    console.log("deleted", fileKey);
}

JSON.JS

[{
    "rskAsesAprvAtchKy": 1001,
    "fileName": "Doc 1",
    "rskAsesRoleAsgnKy": 1277
}]
1
  • Hi, you defined the fileKey var, and it is undefined,, you probably need to do vice verse something like this... fileKey = $scope.attachedDoc.id right? Commented Jul 2, 2015 at 22:42

1 Answer 1

3

You can pass the key as parameter for the ng-click method:

At the view

<li ng-repeat="file in attachedDoc">{{file.fileName}}
     <a href="" ng-click="deleteFile(file.rskAsesAprvAtchKy, $index)"> //Key from the file
        <span class="glyph_remove">
        </span>
     </a>
</li>

Change the delete method

$scope.deleteFile = function(fileKey, fileIndex){
   /*Delete the file*/
   $scope.attachedDoc.splice(fileIndex, 1); //remove the file at position fileIndex 
}

EDIT:

Passing the $index from the ng-repeat and using Array.splice() will do the job. See above.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks it worked i got the id by passing parameter, once i delete the file how can i remove item from list view ?

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.