AngularJS显示参数后重定向 [英] AngularJS Redirecting after displaying the parameter

查看:156
本文介绍了AngularJS显示参数后重定向的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的问题

到目前为止,我甚至没有获得url值。但我现在能够获得url paameter但问题是,我的页面重新导向​​一次显示了警报

So far i didn't even get the url value. But now i can able to get the url paameter but the problem is that my page is getting redirected once showing the alert

下面是我的控制器和路线

Here is my controller and route

路线

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

控制器;

app.controller('ShowUserCtrl', function($scope, $routeParams) {
 var b = $routeParams.UserID;
 alert(b);
    $scope.userid = $routeParams.UserID;
});

我的观点:

{{userid}}

问题是我的网址是这样的。

The problem is My Url is like this

http://192.168.1.58/myapp/#/showprofile/18

显示警报后 18

这使得URL像

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

如何停止重定向??

我只是想这是我最后的网址

I just want this as my final url

http://192.168.1.58/myapp/#/showprofile/18

推荐答案

我发现问题是因为我有功能的 .RUN

I found that the problem is because of .run function that i have.

取出后它的作品不错。

After removing it works good.

下面是我的 .RUN 函数

.run(function ($rootScope, $location, Data, $http) {
            $rootScope.$on("$routeChangeStart", function (event, next, current) {
                $http.post('CheckSession', {}).then(function (results)
                {
                    console.log(results.data);
                    var nextUrl = next.$$route.originalPath;
                    if (nextUrl == '/signin' || nextUrl == '/login' || nextUrl == '/verify' || nextUrl == '/registration' || nextUrl == '/forget' || nextUrl == '/invalidtoken' || nextUrl == '/registersuccess')
                    {
                        console.log('outpages');
                    }
                    else
                    {
                        if (results.data == 1)
                        {
                            console.log('loggedin');
                            console.log(nextUrl);
                            console.log('to be redirect');
                            $location.path(nextUrl);
                        }
                        else {
                            console.log('not logged in');
                            $location.path('login');
                        }
                    }


                });
            });
        });

这篇关于AngularJS显示参数后重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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