作者:lovely蓝衣13 | 来源:互联网 | 2023-07-16 00:34
IhavebeenbeatingmyheadagainstthewalltryingtofigureoutwhyangularJSroutingwontworki
I have been beating my head against the wall trying to figure out why angularJS routing won't work in phonegap for me. I have all the files setup correctly and i don't receive any errors. I'm trying to change the url using the $location.url service directly from angular. So when you tap on a div the controller will have $location.url("profile") for example and nothing will happen. I tried the solution found in this stackoverflow but that's not working for me. Am I doing something wrong, or is there a better way to be approaching this? Following is the routing I have setup
我一直在撞墙,试图找出为什么angularJS路由不能在我的phonegap中工作。我已正确设置所有文件,我没有收到任何错误。我正在尝试直接从angular使用$ location.url服务更改网址。因此,当您点击div时,控制器将具有$ location.url(“profile”),例如,什么都不会发生。我尝试了这个stackoverflow中找到的解决方案,但这对我不起作用。我做错了什么,还是有更好的方法来接近这个?以下是我设置的路由
var app = angular.module("App", ["hmTouchevents"])
.config(function($routeProvider) {
$routeProvider
.when("/index.html", {
templateUrl: "/views/login.html",
controller: "loginCtlr"
})
.when("/landing", {
templateUrl: "/views/landing.html",
controller: "landingCtlr"
})
.when("/single-view/:id", {
templateUrl: "/views/single-view.html",
controller: "singleViewCtlr"
})
.when("/restaurant", {
templateUrl: "/views/restaurant-info.html",
controller: "restaurantCtlr"
})
.when("/profile/:id", {
templateUrl: "/views/profile.html",
controller: "profileCtlr"
})
.when("/lists/:list", {
templateUrl: "/views/lists.html",
controller: "listsCtlr"
})
.when("/follow/:type", {
templateUrl: "/views/follow.html",
controller: "followCtlr"
});
});
A sample controller would be:
样本控制器将是:
app.controller("listsCtlr", ["$scope", "$location", function($scope, $location){
$scope.goTo("profile");
}]);
As always any help is much appreciated.
一如往常,任何帮助都非常感谢。
4 个解决方案