簡體   English   中英

傳遞url參數時出現問題

[英]Issue in passing url parameter

這是我的控制器

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

我有一個這樣的網址

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

當我單擊鏈接時,它會將我重定向到

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

這是我的整個app.js

var app = angular.module('myApp', ['ngRoute', 'ngAnimate', 'toaster']);

app.config(['$routeProvider',
    function ($routeProvider) {
        $routeProvider.
                when('/login', {
                    title: 'Login',
                    templateUrl: 'resources/views/layout/login.php',
                    controller: 'authCtrl'
                })
                .when('/logout', {
                    title: 'Logout',
                    templateUrl: 'resources/views/layout/login.php',
                    controller: 'logoutCtrl'
                })
                .when('/signin', {
                    title: 'Signup',
                    templateUrl: 'resources/views/layout/signin.php',
                    controller: 'authCtrl'
                })
                .when('/registersuccess', {
                    title: 'Dashboard',
                    templateUrl: 'resources/views/layout/register-success.php',
                    controller: 'authCtrl'
                })
                .when('/dashboard', {
                    title: 'Dashboards',
                    templateUrl: 'resources/views/layout/dashboard.php',
                    controller: 'authCtrl'
                })
                .when('/profile', {
                    title: 'Profile',
                    templateUrl: 'resources/views/layout/profile.php',
                    controller: 'authCtrl'
                })
                .when('/contact', {
                    title: 'Contact',
                    templateUrl: 'resources/views/layout/contact.php',
                    controller: 'authCtrl'
                })

                .when('/travel', {
                    title: 'Travel',
                    templateUrl: 'resources/views/layout/travel.php',
                    controller: 'authCtrl'
                })
                .when('/subscription', {
                    title: 'Subscription',
                    templateUrl: 'resources/views/layout/subscription.php',
                    controller: 'authCtrl'
                })

                .when('/invite_friends', {
                    title: 'InviteFriends',
                    templateUrl: 'resources/views/layout/invite_friends.php',
                    controller: 'authCtrl'
                })

                .when('/liked_you', {
                    title: 'LikedYou',
                    templateUrl: 'resources/views/layout/liked_you.php',
                    controller: 'authCtrl'
                })

                .when('/favourites', {
                    title: 'Favourites',
                    templateUrl: 'resources/views/layout/favourites.php',
                    controller: 'authCtrl'
                })

                .when('/coins', {
                    title: 'Subscription',
                    templateUrl: 'resources/views/layout/coins.php',
                    controller: 'authCtrl'
                })

                .when('/forget', {
                    title: 'forget',
                    templateUrl: 'resources/views/layout/forget.php',
                    controller: 'authCtrl'
                })
                .when('/verify', {
                    title: 'verfiy',
                    templateUrl: 'resources/views/layout/verify.php',
                    controller: 'authCtrl'
                })
                .when('/verifyfb', {
                    title: 'verfiyfb',
                    templateUrl: 'resources/views/layout/verifyfb.php',
                    controller: 'authCtrl'
                })
                .when('/registration', {
                    title: 'verfiy',
                    templateUrl: 'resources/views/layout/registration.php',
                    controller: 'authCtrl'
                })


                .when('/showprofile/:UserID', {
                    templateUrl: 'resources/views/layout/showprofdile.php',
                    controller: 'renameShowCtrl',

                  })
                .when('/', {
                    title: 'Login',
                    templateUrl: 'resources/views/layout/login.php',
                    controller: 'authCtrl',
                    role: '0'
                })
                .when('/invalidtoken', {
                    title: 'Login',
                    templateUrl: 'resources/views/layout/invalidtoken.php',
                    controller: 'authCtrl',
                    role: '0'
                })


    }])
        .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');
                        }
                    }


                });
            });
        });


        app.controller('ShowOrderController', function($scope, $routeParams) {

    $scope.UserIDs = $routeParams.UserIDs;

});


  $scope.customNavigate=function(msg){
       $location.path("/view2"+msg)
    }

如何在視圖中顯示參數8

這是我的authCtrl.js

幫助請

我正在幫助我的朋友問..

您可以使用$ routeParams獲取路線參數。

就您而言,您在控制器中的代碼可能類似於:

function ctrl($scope, $routeParams) {
        $scope.userId = $routeParams.UserID
    }

您認為使用綁定表達式{{userId}}

正確的方法是在url中傳遞id參數

/showprofile/{UserID}

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM