Używam angularJS, aby ustawić, gdzie ma iść strona po zalogowaniu, ale jeśli mam tylko to
function routeProviderFunction($routeProvider){
$routeProvider.when("/default",{
templateUrl: "HTML/login.html",
controller: funct2
});
$routeProvider.otherwise({
redirectTo: "/default"
});
}
Mój dostawca trasy działa w powyższym kodzie, ale po przekształceniu go w to
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"
});
}
Mój dostawca tras w ogóle przestaje działać. Jakieś pomysły
Odpowiedzi:
2 dla odpowiedzi № 1spróbuj zrobić tak:
$routeProvider
.when("/default", {
templateUrl: "HTML/login.html",
controller : "funct2"
}).when("/adminMenu/:username", {
templateUrl: "HTML/adminMenu.html",
controller : "adminMenu"
}).otherwise({
redirectTo : "/default"
});
0 dla odpowiedzi nr 2
Czy kontroler adminMenu istnieje w pliku globalprzestrzeń nazw? Naciśnij klawisz F12 i sprawdź konsolę błędów. Angular ma całkiem przyzwoite komunikaty o błędach. Warto również zauważyć, że „when” można łączyć w łańcuchy, więc powinieneś robić coś takiego jak ta route.when (). When (). W przeciwnym razie ();
0 dla odpowiedzi № 3
Po sprawdzeniu odpowiedzi @fabuloso kliknęło mnie, czego potrzebowałem, aby naprawić mój problem.
miałem
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"
});
});
dodając ostatnią część "contactUs" zauważyłem, że po trasie giftCards mam średnik, który wszystko wysadza.