获取AngularJS中的url参数查询字符串。

时间:2022-04-30 18:52:01

I have a url like this.

我有一个这样的url。

www.website.com/user.html?name=abcd

I want to get query string from the link on user.html page by angularjs.

我想从用户的链接中获取查询字符串。由angularjs html页面。

I am trying to get it by location.search()

我正试图找到它。搜索()

     var formApp = angular.module('formApp', []);
        var user;
formApp.controller('formProfile1', function($scope,$http,$location){
user =$location.search().name;
        alert(user);

Problem is when I run above code I am getting error undefined.

问题是当我运行上面的代码时,我的错误没有定义。

1 个解决方案

#1


1  

You can check

你可以检查

https://docs.angularjs.org/api/ngRoute/service/$routeParams

https://docs.angularjs.org/api/ngRoute/service/ routeParams美元

also routing can be hell sometimes so please look at this solution.. that saved my life

有时路由也可能是地狱,所以请看看这个解决方案。这救了我的命

https://ui-router.github.io/guide/states

https://ui-router.github.io/guide/states

#1


1  

You can check

你可以检查

https://docs.angularjs.org/api/ngRoute/service/$routeParams

https://docs.angularjs.org/api/ngRoute/service/ routeParams美元

also routing can be hell sometimes so please look at this solution.. that saved my life

有时路由也可能是地狱,所以请看看这个解决方案。这救了我的命

https://ui-router.github.io/guide/states

https://ui-router.github.io/guide/states