0

I want to create a directive that would set a correct url referenced from the directive's template.

  datsApp.directive('myDir', function () {
        return {
            restrict: 'A',
            scope: {},
            link: function (scope) {
                scope.url = link;
            },
            template: "<span>Click <a href='{{url}}'>here</a> for more info</span>"
        };
    });

The link variable is a global variable that holds a url and depends on the language and some other settings. If I set link = 'www.google.com', I get it pointing to localhost:8888/somedir/www.google.com

How can I fix this?

1 Answer 1

1

If you are adding an absolute address, start with http://whatever.address. This is because when you are adding the link without any Slash or without defining the protocol, the url is understood as a relative address. It is relative to your current location. This is why the Google.com is being appended to your current url

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

1 Comment

Thank you! Such a silly mistake - but now I have learned smth new :)

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.