0

We have a page that is using AngularJS. I am creating a link:

<div ng-if="breakout.AttachmentFiles">
    <div ng-repeat="file in breakout.AttachmentFiles" style="display: flex; align-items:baseline;">
        <b style="width: 95px; text-align: right">Attachments:</b>
        <a href="file.Url">{{file.Url}}</a>
    </div>
</div>

File structure is:

  else if (itemKey === "AttachmentFiles") {
    var foobar = [];

    angular.forEach(itemValue.results, function(value, key) {
      foobar.push({"Url": $location.$$host+value.ServerRelativeUrl+"", "FileName": value.FileName});
    });


    console.log("AttachmentFiles | foobar: ", foobar);

    currentBreakout[itemKey] = foobar;
  }

enter image description here

For the text of the href displays the correct url, but the link it self goes off to a /Pages/file.Url:

enter image description here

What am I doing wrong?

EDIT:

I changed

<a href="file.Url">{{file.Url}}</a>

to

<a href={{file.Url}}>{{file.Url}}</a>

and that gives me a new link:

enter image description here

So for some reason https://company.sharepoint.com/sites/siteName/Pages/ is being inserted before the actual URL.

Solved:

With the help from Ganash's post about using {{}} instead of "" and adding http:// to the url, the link is now working correctly.

1
  • After it creates a link, inspect the anchor element and check if it creates a link correctly or not. Commented Mar 19, 2019 at 16:06

1 Answer 1

1

Try using:

<a href="{{file.Url}}">{{file.Url}</a>

Or

<a ng-href="file.Url">{{file.Url}}</a>
4
  • The {{}} got me the actual URL in it now, but for some reason the https://companyName.sharepoint.com/sites/siteName/pages is being inserted before the URL I want. Commented Mar 19, 2019 at 16:17
  • Then you must be creating wrong url after fetching the attachments and adding in foobar. Commented Mar 19, 2019 at 16:34
  • I agree. I don't know where. This is AngularJS which I am not not familiar with at all. Commented Mar 19, 2019 at 16:37
  • 1
    I needed to include http:// in the url, now it is working as intended. Commented Mar 19, 2019 at 17:12

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.