android - Ionic $urlRouterProvider.otherwise() not working -
i've tried following tutorials looking @ other stackoverflow questions can't figure i'm doing wrong.
i built ionic creator , i'm trying have user login google , after that's complete route dashboard.
sorry brand new me. if can explain i'm doing wrong , why way, can learn. thanks!
my controller.js:
angular.module('app.controllers', []) .controller('loginctrl', ['$scope', '$stateparams', // following constructor function page's controller. see https://docs.angularjs.org/guide/controller // can include angular dependencies parameters function // tip: access route parameters 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){ // gives google access token. can use access google api. var token = results.credential.accesstoken; // signed-in user info. var user = results.user; console.log(user); $urlrouterprovider.otherwise('/dashboard'); //window.location.href = "dashboard.html"; }); } }])
my 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>
routes.js:
angular.module('app.routes', []) .config(function($stateprovider, $urlrouterprovider) { // ionic uses angularui router uses concept of states // learn more here: https://github.com/angular-ui/ui-router // set various states app can in. // each state's controller can 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') });
your js should this
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 may use location below //$location.path('/dashboard'); }); } }])
Comments
Post a Comment