简体   繁体   English

从Angular.js中的自定义链接获取URL参数

[英]Get URL parameters from custom link in Angular.js

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? 我有一种解析自定义URL的方法(不是通过$location服务,即不是浏览器当前指向的URL)并提取/处理Angular.js中的URL属性? 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. Anchor为您提供了一些解析给定URL的功能。 On the provided jsfiddle link you can test it. 在提供的jsfiddle链接上,您可以对其进行测试。


function AppCtrl($scope) {

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

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

}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM