gpt4 book ai didi

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

转载 作者:搜寻专家 更新时间:2023-11-01 09:39:49 25 4
gpt4 key购买 nike

我试过学习教程并查看其他 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";
});
}
}])

我的 login.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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com