[英]Fetch URL parameters using angular.js
Hi I have a URL below:- 嗨,我的网址如下:-
http://localhost:8080/test/rpw.html?u=64603549618667520&v=7816fb816d1c6bc85b77b372cc5e5eb9 http:// localhost:8080 / test / rpw.html?u = 64603549618667520&v = 7816fb816d1c6bc85b77b372cc5e5eb9
I want to fetch the value of u & v parameter in the controller, How it can be done please give a detailed description with example 我想在控制器中获取u&v参数的值,如何完成,请通过示例给出详细说明
Adding the code snippet 添加代码段
<script>
var app = angular.module('resetPasswd',['ngRoute']);
app.controller('passwordCtrl', [$routeParams, function($scope,$routeParams)
{
var params = $routeParams;
alert("check value "+params.u);
}]);
Inject '$routeParams' into a controller as such and access the $routeParams object and there you have it. 像这样将“ $ routeParams”注入到控制器中,并访问$ routeParams对象,就可以了。
angular.module('app')
.controller('DummyController', ['$routeParams', function($routeParams) {
var params = $routeParams;
}
The above $routeParams gives your controller access to all the parameters in the url in the form of a nice object therefore you are able to access the url parameters very easily. 上面的$ routeParams使您的控制器可以以很好的对象的形式访问url中的所有参数,因此您可以非常轻松地访问url参数。 In this case you could do params.u and that would give you your u parameter.
在这种情况下,您可以执行params.u,这将为您提供u参数。
Make sure you injected the ngRoute service into your app beforehand or the above $routeParams won't work. 请确保您事先将ngRoute服务注入了您的应用程序,否则上述$ routeParams无效。
angular.module('app', ['ngRoute']);
Reference : 参考:
https://docs.angularjs.org/api/ngRoute
https://docs.angularjs.org/api/ngRoute
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.