2016-10-15 3 views
1

이것은 로그인 페이지가 대체 시스템으로 사용될 때만 발생합니다. 기본 페이지가 폴백으로 사용되면 동일한 로그인 페이지가 정상적으로 작동합니다. 나는이 프레임 워크에 매우 익숙하며, 이것을 고치는 데 도움이된다면 많은 도움이 될 것입니다. 이 문제를 해결하기 위해 다른 코드가 필요한지 물어보십시오. 미리 감사드립니다! 이것은 내 loginCtrl (로그인 컨트롤러)입니다이온 - 로그인 페이지가 메인 페이지로 리디렉션되지 않음

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

    .state('app', { 
    url: '/app', 
    abstract: true, 
    templateUrl: 'templates/menu.html' 
}) 

.state('app.login', { 
    url: '/login', 
    views: { 
     'menuContent': { 
      templateUrl: 'templates/login.html', 
      controller: 'AppCtrl' 
     } 
    }, 
    authenticate: false 
}) 

.state('app.search', { 
    url: '/search', 
    views: { 
     'menuContent': { 
      templateUrl: 'templates/search.html', 
      controller: 'mainCtrl' 
     } 
    } 
}) 

.state('app.browse', { 
     url: '/browse', 
     views: { 
      'menuContent': { 
       templateUrl: 'templates/browse.html', 
       controller: 'mainCtrl' 
      } 
     } 
    }) 
    .state('app.playlists', { 
     url: '/playlists', 
     views: { 
      'menuContent': { 
       templateUrl: 'templates/playlists.html', 
       controller: 'PlaylistsCtrl' 
      } 
     } 
    }) 

.state('app.snapshot', { 
    url: '/snapshot', 
    views: { 
     'menuContent': { 
      templateUrl: 'templates/snapshot.html' 
     } 
    } 
}) 

.state('app.callqueues', { 
    url: '/callqueues', 
    views: { 
     'menuContent': { 
      templateUrl: 'templates/callqueues.html' 
     } 
    } 
}) 

.state('app.single', { 
    url: '/playlists/:playlistId', 
    views: { 
     'menuContent': { 
      templateUrl: 'templates/playlist.html', 
      controller: 'PlaylistCtrl' 
     } 
    } 
}); 
// if none of the above states are matched, use this as the fallback 
// $urlRouterProvider.otherwise('/app/search'); 
$urlRouterProvider.otherwise('/app/login'); 
}); 

다음

내 설정은,

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

.controller('AppCtrl', function($scope, $ionicModal, $timeout, $location, $http, $log, $state) { 

// With the new view caching in Ionic, Controllers are only called 
// when they are recreated or on app start, instead of every page change. 
// To listen for when this page is active (for example, to refresh data), 
// listen for the $ionicView.enter event: 
//$scope.$on('$ionicView.enter', function(e) { 
//}); 

// Form data for the login modal 
$scope.loginData = {}; 

// Create the login modal that we will use later 
// $ionicModal.fromTemplateUrl('templates/login.html', { 
//  scope: $scope 
// }).then(function(modal) { 
//  $scope.modal = modal; 
// }); 

// Triggered in the login modal to close it 
// $scope.closeLogin = function() { 
//  $scope.modal.hide(); 
// }; 

// Open the login modal 
// $scope.login = function() { 
//  $scope.modal.show(); 
// }; 

$scope.chartConfig = { 
    options: { 
     chart: { 
      type: 'bar' 
     } 
    }, 
    series: [{ 
     data: [10, 15, 12, 8, 7] 
    }], 
    title: { 
     text: 'Hello' 
    }, 

    loading: false 
}; 

// Perform the login action when the user submits the login form 
$scope.doLogin = function() { 
    console.log('Doing login', $scope.loginData); 
    var username = $scope.loginData.name; 
    var password = $scope.loginData.password; 
    console.log("username" + $scope.loginData.name); 
    if (username == "[email protected]" && password == "admin") { 
     console.log("if part"); 
     $location.path("#/app/search"); 
    } else { 
     console.log("error"); 
     // $("#errorpwd").css({"display":"block"}); 
     // $scope.message = "Error"; 
     // $scope.messagecolor = "alert alert-danger"; 
    } 
    // Simulate a login delay. Remove this and replace with your login 
    // code if using a login system 
    // $timeout(function() { 
    //  $scope.closeLogin(); 
    // }, 1000); 
}; 
}) 

마침내 내 로그인 HTML 코드,

<ion-view view-title="Login" name="login-view"> 
<ion-header-bar class="bar bar-header bar-positive"> 
    <h1 class="title">Login</h1> 
    <!--<button class="button button-clear button-primary icon-left ion-close-circled" ng-click="modal.hide()"></button>--> 
</ion-header-bar> 
<ion-content> 
    <form ng-submit="doLogin()"> 
     <div class="list"> 
      <label class="item item-input"> 
     <span class="input-label">Username</span> 
     <input type="text" ng-model="loginData.name"> 
    </label> 
      <label class="item item-input"> 
     <span class="input-label">Password</span> 
     <input type="password" ng-model="loginData.password"> 
    </label> 
      <label class="item"> 
     <button nav-clear class="button button-block button-positive" type="submit">Log in</button> 
    </label> 
     </div> 
    </form> 
</ion-content> 

입니다

답변

1

당신은 구약

angular.module('starter.controllers', ['ui.router']); 

도 @sajeetharan 날 도와위한 ui.router위한

<!-- Angular --> 
    <script src="//ajax.googleapis.com/ajax/libs/angularjs/1.2.4/angular.min.js"></script> 
    <!-- UI-Router --> 
    <script src="//angular-ui.github.io/ui-router/release/angular-ui-router.js"></script> 
+0

덕분 JS를 참조 모듈 종속성으로 UI 라우터 주입. "$ location.path()"를 "$ state.go()"로 변경해 보았습니다. 놀랍게도 그것은 매력처럼 작동합니다. 나는 당신의 대답을 고맙게 생각합니다. – Gowtham

+0

@Gowtham 도움이 되었다면 답으로 표시 – Sajeetharan

관련 문제