angularjs – 如何在角度和离子中重定向到另一个页面

前端之家收集整理的这篇文章主要介绍了angularjs – 如何在角度和离子中重定向到另一个页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我在使用角度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,$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',$ionicLoading) {

})

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

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

解决方法

使用这个$state.go(‘app.main’);

猜你在找的Angularjs相关文章