ax1mx2
ax1mx2

Reputation: 704

Get URL parameters from custom link in Angular.js

I there a way to parse custom URL (not through the $location service, i.e. not the one the browser is currently pointing to) and extract/manipulate the URL attributes in Angular.js? I need this, in order to pass some links to a directive in side the controller, but first I have to construct them.

For example:

//test/query?e=1&page=10

And the requested output should be similar to this:

{ host: 'test', resource: 'query', search: { e: '1', page: '10' } }

Upvotes: 0

Views: 365

Answers (1)

burovmarley
burovmarley

Reputation: 644

Look at this maybe this is enough for you. Anchor gives you some functions for parsing given url. On the provided jsfiddle link you can test it.


function AppCtrl($scope) {

    $scope.$watch('url', function () {
        $scope.parser.href = $scope.url;
    });

    $scope.init = function () {
        $scope.parser = document.createElement('a');
        $scope.url = window.location;
    }

}

Upvotes: 1

Related Questions