4

我在使用 Angular js 进行离子重定向时遇到问题。这是我的代码

app.js

angular.module('test', ['ionic', 'test.controllers', ])

.run(function($rootScope, $state, $ionicPlatform, $window) {
    $ionicPlatform.ready(function() {
        if (window.cordova && window.cordova.plugins.Keyboard) {
            cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);
        }
        if (window.StatusBar) {
            // org.apache.cordova.statusbar required
            StatusBar.styleDefault();
        }
    });
})

.config(function($stateProvider, $urlRouterProvider) {
    $stateProvider

        .state('opener', {
            cache: false,
            url: '/opener',
            templateUrl: 'templates/opener.html',
            controller: 'appController'
        })
        .state('app.main', {
            url: '/main',
            views: {
                'menuContent': {
                    templateUrl: 'templates/main.html',
                    controller: 'mainController'
                }
            }
        })
        .state('app', {
            url: '/app',
            abstract: true,
            templateUrl: 'templates/menu.html',
            controller: 'menuController'
        })
    $urlRouterProvider.otherwise('/opener');
})


// controllers.js file 


angular.module('test.controllers', [])

.controller('appController', function($scope, $state, $location) {
        $scope.gotoMain = function() {
            window.localStorage['UserSession'] = 'NOT_LOGIN';
            $location.path("/templates/main");
        }
    })
    .controller('menuController', function($scope) {
        $scope.myClass = "ion-navicon";
        $scope.toggleLeft = function() {
            if ($scope.myClass === "ion-navicon")
                $scope.myClass = "ion-arrow-left-c";
            else
                $scope.myClass = "ion-navicon";
        };
    })

// Main Screen Controller
.controller('mainController', function($scope, $state, $ionicLoading) {

})

在我使用的代码中$location.path('/path');

但我也尝试过$state.go('/path'); 请帮我解决这个问题。

4

2 回答 2

2

用这个 $state.go('app.main');

于 2015-12-24T08:51:25.130 回答
1

尝试$state像这样使用,

$scope.gotoMain = function() {
    window.localStorage['UserSession'] = 'NOT_LOGIN';
     $state.go('main', {});
}
于 2015-11-10T11:25:23.697 回答