kan*_*sen 6 angularjs nested-views ionic
我正在开发一款应用程序,使用Ionic进行构建.我的问题是$ state.go只能在浏览器中工作,但不能在手机上工作.这似乎是一个常见的问题,但在阅读了相同问题的大量答案后,我仍然无法弄清楚如何解决它.
一般修复似乎是为了确保您使用相对URL,如下所述:使用带有Phonegap的Angular UI-Router,但我仍然无法使其工作.我错过了什么?
链接到plunker:http://plnkr.co/edit/qFJ1Ld6bhKvKMkSmYQC8?p = preview
App.js结构:
....
$stateProvider
.state('parent', {
url: "/",
templateUrl: "parent.html"
})
.state('parent.child', {
url: "child",
templateUrl: "child.html"
})
$urlRouterProvider.otherwise("/")
})
....
Run Code Online (Sandbox Code Playgroud)
为了让 state.go 工作,你必须将 $state 依赖注入到你的控制器中
app.controller('ParentCtrl', ['$scope', '$state', function($scope, $state) {
$scope.$state = $state
}]);
app.controller('MenuCtrl', ['$scope', '$state', function($scope, $state){
$scope.goTo = function(){
$state.go('menu.kategorier');
}
}]);
Run Code Online (Sandbox Code Playgroud)
并且你必须在 $stateProvider 中注册你想要进入的状态
$stateProvider
.state('menu.kategorier', {...})
Run Code Online (Sandbox Code Playgroud)
要到达该状态,您必须从父状态(如本例中的“菜单”)进入。您无法将状态从“parent”更改为“menu.kategorier”,但可以从“parent”转到“parent.child”