android - ionic $urlRouterProvider.otherwise() 不工作

标签 android angularjs ionic-framework firebase-authentication google-signin

我尝试遵循教程并查看其他 stackoverflow 问题,但我不知道我做错了什么。

我用 ionic Creator 构建了这个,现在我尝试让用户登录 Google,然后完成到我的仪表板的路由。

抱歉,这对我来说是全新的。如果你能解释我做错了什么以及为什么会这样,这样我就可以学习。谢谢!

我的controller.js:

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

.controller('loginCtrl', ['$scope', '$stateParams', // The following is the constructor function for this page's controller. See https://docs.angularjs.org/guide/controller
// You can include any angular dependencies as parameters for this function
// TIP: Access Route Parameters for your page via $stateParams.parameterName
function ($scope, $stateParams, $urlRouterProvider) {

    $scope.googlelogin = function(){
        //alert('yup');
        var provider = new firebase.auth.GoogleAuthProvider();
        provider.addScope('https://www.googleapis.com/auth/plus.login');
        firebase.auth().signInWithPopup(provider).then(function(results){
            // This gives you a Google Access Token. You can use it to access the Google API.
            var token = results.credential.accessToken;
            // The signed-in user info.
            var user = results.user;
            console.log(user);

            $urlRouterProvider.otherwise('/dashboard');
            //window.location.href = "dashboard.html";
        });
    }
}])

我的登录.html:

<ion-view title="Login" hide-nav-bar="true" id="page4">
    <ion-content padding="true" class="manual-ios-statusbar-padding">
        <form id="login-form1" class="list">
            <div class="spacer" style="width: 300px; height: 40px;"></div>
            <div>
                <img src="img/7TKZQZBSSg62UJQB4zyu_logo.png" width="30%" height="auto" style="display: block; margin-left: auto; margin-right: auto;">
           </div>
           <div class="spacer" style="width: 300px; height: 100px;"></div>
           <a id="login-button1" class="button button-stable  button-block" ng-click="googlelogin()">Google Login</a>
           <button id="login-button3" class="button button-stable  button-block">Facebook Login</button>
       </form>
   </ion-content>
</ion-view>

路由.js:

angular.module('app.routes', [])

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

    // Ionic uses AngularUI Router which uses the concept of states
    // Learn more here: https://github.com/angular-ui/ui-router
    // Set up the various states which the app can be in.
    // Each state's controller can be found in controllers.js
    $stateProvider



    .state('menu.dashboard', {
        url: '/dashboard',
        views: {
            'side-menu21': {
                templateUrl: 'templates/dashboard.html',
                controller: 'dashboardCtrl'
             }
        }
    })

    .state('login', {
        url: '/login',
        templateUrl: 'templates/login.html',
        controller: 'loginCtrl'
    })

$urlRouterProvider.otherwise('/side-menu21/dashboard')
});

最佳答案

你的js应该是这样的

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

    .controller('loginCtrl', ['$scope', '$stateParams', '$state','$location',
    function ($scope, $stateParams,$state,$location, $urlRouterProvider) {

        $scope.googlelogin = function(){

            var provider = new firebase.auth.GoogleAuthProvider();
            provider.addScope('https://www.googleapis.com/auth/plus.login');
            firebase.auth().signInWithPopup(provider).then(function(results){

                var token = results.credential.accessToken;

                var user = results.user;
                console.log(user);

               $state.go('menu.dashboard'); 

//or you may use location like below
//$location.path('/dashboard');
                });
            }
        }])

关于android - ionic $urlRouterProvider.otherwise() 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40486879/

相关文章:

android - PagedList 已弃用

java - 用于apk文件逆向工程的dex2jar classes.dex文件出错

javascript - 尝试在 ionic 上多次加载 Angular

cordova - ionic android 构建失败 'CordovaLib'

带有选项卡的 Android ViewPager 在屏幕旋转后不保持状态

android - 了解 Gradle (Android Studio) 有多重要?

javascript - Angular 在 URL 中获取值

javascript - 如何添加基于多变量比较的ng-class?

单击链接后 Angularjs 更改 View 模板

typescript - 在 xcode 上编译应用程序时出现 ionic3 sqlite 错误