質問

Im using angularJS to set where i want the page to go after i login, but if i only have this

function routeProviderFunction($routeProvider){
$routeProvider.when('/default',{
    templateUrl: 'HTML/login.html',
    controller: funct2
});

$routeProvider.otherwise({
    redirectTo: '/default'
});
}

My route provider works in the above code, but after i turn it into this

    function routeProviderFunction($routeProvider){
$routeProvider.when('/default',{
    templateUrl: 'HTML/login.html',
    controller: funct2
});
$routeProvider.when('/adminMenu/:username', {
     templateUrl: 'HTML/adminMenu.html',
     controller: adminMenu
     });


$routeProvider.otherwise({
    redirectTo: '/default'
});
}

My route provider ceases to work at all. Any ideas

役に立ちましたか?

解決

try to do like this:

$routeProvider
            .when('/default', {
                templateUrl: 'HTML/login.html',
                controller : 'funct2'
            }).when('/adminMenu/:username', {
                templateUrl: 'HTML/adminMenu.html',
                controller : 'adminMenu'
            }).otherwise({
                redirectTo : '/default'
            });

他のヒント

Does the controller adminMenu exist in the global namespace? Press F12 and check the error console. Angular has quite decent error messages. Also worth noting that 'when' is chainable so you should be doing something like this route.when().when().otherwise();

After looking @fabuloso answer, it clicked to me what I needed to fix my problem.

I had

pageApp.config(function($routeProvider) {
    $routeProvider

        // route for the home page
        .when('/', {
            templateUrl : 'content/home.html',
            controller  : 'homeController'
        })

        // route for the directions page
        .when('/directions', {
            templateUrl : 'content/directions.html',
            controller  : 'directionsController'
        })

        // route for the giftCards page
        .when('/giftCards', {
            templateUrl : 'content/giftCards.html',
            controller  : 'giftCardsController'
        });

        // route for the giftCards page
        .when('/contactUs', {
            templateUrl : 'content/contactUs.html',
            controller  : 'contactUsController'
        });

});

when adding the last "contactUs" part, I noticed I had a semicolon after the giftCards route, which blows up everything.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top