0

Problem:

I am showing a list of documents in my application and one of the fields is a preview icon which shows a modal to display a pdf preview of the document. I am building a url to make it dynamic but I'm not sure how to iterate through the array

Controller:

$scope.documentIdentifier = documents.documentBag[0].documentId;
$scope.url = $sce.trustAsResourceUrl("http://localhost:3000/services/v1/" + $scope.documentId + "?type=pdf");

My object:

    {
      "documents": "Success",
      "documentBag": [
        {
          "documentId": "E1DUPW9JPP1GUI3"
        },
        {
          "documentId": "E1FUJW5JPP1GUI4"
        },
        {
          "documentId": "G1DUJW3JPP1GUI5"
        }
      ]
    }

I need to iterate through the documentId to show all 3 documents but not exactly sure how.

1
  • 1
    ngRepeat might shed some light. Commented Nov 30, 2016 at 22:05

1 Answer 1

2

Use ng-Repeat to iterate over the array and build your url.

$scope.documents = documents.documentBag;
$scope.url = $sce.trustAsResourceUrl("http://localhost:3000/services/v1/");

<div ng-repeat="document in documents">
    {{url + document.documentId}}
</div>
Sign up to request clarification or add additional context in comments.

2 Comments

is there a way for me to iterate in the controller? because i have to put ?type=pdf at the end of the url
In that case you can do {{url + document.documentId + '?type=pdf'}} in your HTML. If you really want to iterate in the controller you can build the urls with a forEach over the array.

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.