I there a way to parse custom URL (not through the $location
service, ie 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' } }
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;
}
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.