Reputation: 704
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
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