0

I made a directive for automatically add links for a html validation, like that :

.directive('validationhtml', function($rootScope, $location) {
    return {
        restrict: 'A',
        template: '<a href="" data-ng-click="createTab(getUrl(), $event);" title="validation html">validation html</a>',
        controller: function($scope, $location) {
            $scope.getUrl = function() {
                var url = 'http://validator.w3.org/check?uri=' + $location.path;
                console.log(url);
                return url;
            }
        }
    };
})

createTab(); is a function in rootscope, and correctly executed (new tab), but getUrl(); have a problem: the url is not good, in the return i have this

http://validator.w3.org/check?uri=function (c){if(B(c))return this[b];this[b]=a(c);this.$$compose();return this}

what's wrong ?

2 Answers 2

1

It should be location.path().

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

2 Comments

thks, but now there is 'validator.w3.org/check?uri=' and a blank, even with $sce
$location.path() return the path of your current page (ex. for www.example.com/foo/bar it returns foo/bar). If you use it on a page without path (ex. www.example.com) the result will be an empty string. If you want to retrieve the full URL of your page you must use $location.absUrl().
1

$location path is a function:

var url = 'http://validator.w3.org/check?uri=' + $location.path();

2 Comments

thks, but now there is 'validator.w3.org/check?uri=' and a blank, even with $sce
How about $location.absUrl(); is that empty, too?

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.