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

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

问题描述

这是我的控制器代码

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

我通过 url 传递参数.

I am passing the parameter by url.

我正在尝试像这样直接通过 url 访问此页面

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

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

但它把我重定向到

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

如何在我的视图中获取 url 值?

How can i get the url value in my view ?

这是我的 app.js,这是我的 authCtrl.js

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

推荐答案

在你的控制器中试试这个,它会根据 url 值返回对象,然后我们就可以像这样得到尊重的值

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 - 尝试从 url 获取参数时,页面重定向到 angular js 中的其他页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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