AngularJS - 页面重定向到角的js其他页面,同时试图从url参数 [英] AngularJS - Page redirecting to some other page in angular js while trying to get parameter from url

查看:93
本文介绍了AngularJS - 页面重定向到角的js其他页面,同时试图从url参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的控制器code

 。当('/ showprofile /:用户名',{
      templateUrl:资源/视图/布局/ showprofile.php',
      控制器:'ShowOrderController',
     })

我通过URL传递的参数。

我想通过URL直接像这样访问此页

http://192.168.1.58/myapp/#/showprofile/8

但它重定向我

http://192.168.1.58/myapp/#/showprofile/:UserID

我怎样才能在我看来,url值?

下面是我的 app.js 这里是我的 authCtrl.js


解决方案

在你的控制器试试这个,它会返回基于URL值的对象,然后我们可以得到尊重的价值是这样

\r
\r

//将返回对象\r
的console.log($ routeParams);\r
\r
//得到这样的具体url值\r
的console.log($ routeParams.UserID);\r
   要么\r
的console.log($ route.current.params.UserID);

\r

\r
\r

Here's my controller code

.when('/showprofile/:UserID', {
      templateUrl: 'resources/views/layout/showprofile.php',
      controller: 'ShowOrderController',
     })

I am passing the parameter by url.

I am trying to access this page by the url directly like this

http://192.168.1.58/myapp/#/showprofile/8

But it is redirecting me to

http://192.168.1.58/myapp/#/showprofile/:UserID

How can i get the url value in my view ?

Here is my app.js and here is my authCtrl.js

解决方案

Try this in your controller, it will return the object based on url value then we can get the respected value like this

//it will return the object
console.log($routeParams);

//get the specific url value like this
console.log($routeParams.UserID);
   or
console.log($route.current.params.UserID);

这篇关于AngularJS - 页面重定向到角的js其他页面,同时试图从url参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆