2017-08-14 61 views
0

我收到空白頁與離子。在chrome調試器中沒有顯示錯誤。當我檢查調試器時,我在ion-nav-view內沒有看到任何內容,這意味着由於某種原因,ui路由器不工作。需要幫助來找出錯誤。離子顯示一個沒有任何錯誤的空白頁面

這裏是我的代碼:

的index.html:

<!DOCTYPE html> 
<html> 
    <head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="initial-scale=1, maximum-scale=1, user-scalable=no, width=device-width"> 
    <title></title> 

    <link rel="manifest" href="manifest.json"> 

    <!-- un-comment this code to enable service worker 
    <script> 
     if ('serviceWorker' in navigator) { 
     navigator.serviceWorker.register('service-worker.js') 
      .then(() => console.log('service worker installed')) 
      .catch(err => console.log('Error', err)); 
     } 
    </script>--> 

    <link href="lib/ionic/css/ionic.css" rel="stylesheet"> 
    <link href="css/style.css" rel="stylesheet"> 

    <!-- IF using Sass (run gulp sass first), then uncomment below and remove the CSS includes above 
    <link href="css/ionic.app.css" rel="stylesheet"> 
    --> 

    <!-- ionic/angularjs js --> 
    <script src="lib/ionic/js/ionic.bundle.js"></script> 
    <script src="lib/ionic/js/angular/angular-resource.min.js"></script> 
    <script src="lib/ionic/js/angular-ui/angular-ui-router.min.js"></script> 
    <script src="lib/ngCordova/dist/ng-cordova.js"></script> 

    <!-- cordova script (this will be a 404 during development) --> 
    <script src="cordova.js"></script> 

    <!-- your app's js --> 
    <script src="js/app.js"></script> 
    <script src="js/services.js"></script> 
    <script src="js/controllers.js"></script> 
    </head> 

    <body ng-app="watchHoursApp"> 
    <ion-nav-view> 
    </ion-nav-view> 
    </body> 
</html> 

menu.html:

<ion-side-menus enable-menu-with-back-views="false"> 
    <ion-side-menu-content> 
    <ion-nav-bar class="bar-stable"> 
     <ion-nav-back-button> 
     </ion-nav-back-button> 

     <ion-nav-buttons side="left"> 
     <button class="button button-icon button-clear ion-navicon" menu-toggle="left"> 
     </button> 
     </ion-nav-buttons> 
    </ion-nav-bar> 
    <ion-nav-view name="menuContent"></ion-nav-view> 
    </ion-side-menu-content> 

    <ion-side-menu side="left"> 
    <ion-header-bar class="bar-stable" > 
     <h1 class="title">watchHours</h1> 
    </ion-header-bar> 
    <ion-content> 
     <ion-list> 
     <ion-item menu-close ui-sref="app"> 
      HOME 
     </ion-item> 
     <ion-item menu-close ng-if="currentUser" ui-sref="app.user({id: uid})"> 
      {{username}} 
     </ion-item> 
     <ion-item menu-close ui-sref="app.search"> 
      TV SHOWS 
     </ion-item> 
     <ion-item menu-close ng-if="!currentUser" ng-click="login()"> 
      Log in 
     </ion-item> 
     <ion-item menu-close ng-if="!currentUser" ng-click="register()"> 
      Sign up 
     </ion-item> 
     <ion-item menu-close ng-if="currentUser" ng-click="logout()"> 
      Log out 
     </ion-item> 
     </ion-list> 
    </ion-content> 
    </ion-side-menu> 
</ion-side-menus> 

app.js:

// Ionic Starter App 

// angular.module is a global place for creating, registering and retrieving Angular modules 
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html) 
// the 2nd parameter is an array of 'requires' 
// 'starter.controllers' is found in controllers.js 
angular.module('watchHoursApp', ['ionic']) 

.run(function($ionicPlatform) { 
    $ionicPlatform.ready(function() { 
    // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard 
    // for form inputs) 
    if (window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
     cordova.plugins.Keyboard.disableScroll(true); 

    } 
    if (window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleDefault(); 
    } 
    }); 
}) 

.config(function($stateProvider, $urlRouterProvider) { 
    $stateProvider 
    .state('app', { 
     url: '/app', 
     abstract: true, 
     templateUrl: 'templates/menu.html', 
     controller: 'SidemenuCtrl' 
    }); 
    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/app'); 
}); 

controller.js:

angular.module('watchHoursApp') 

.controller('SidemenuCtrl', ['$scope', '$state', '$rootScope', 'Shows', '$http', 
    '$location', '$localStorage', 'HomeServices', 'AuthFactory', 
    '$ionicModal', '$ionicSideMenuDelegate', '$timeout', 
    function ($scope, $state, $rootScope, Shows, $http, 
    $location, $localStorage, HomeServices, 
    AuthFactory, $ionicModal, $ionicSideMenuDelegate, $timeout) { 
    console.log("Hello"); 
    // 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 = $localStorage.getObject('userinfo','{}'); 
    $scope.reservation = {}; 
    $scope.registration = {}; 
    $rootScope.currentUser = false; 
    $rootScope.username = ''; 
    $rootScope.admin = false; 
    $rootScope.uid = ''; 
    $rootScope.isVerified = false; 

    if(AuthFactory.isAuthenticated()) { 
     $rootScope.currentUser = true; 
     $rootScope.username = AuthFactory.getUsername(); 
     $rootScope.admin = AuthFactory.isAdmin(); 
     $rootScope.isVerified = AuthFactory.isVerified(); 
     $rootScope.uid = AuthFactory.uid(); 
    } 

    // 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(); 
    }; 

    // Perform the login action when the user submits the login form 
    $scope.doLogin = function() { 
     console.log('Doing login', $scope.loginData); 
     $localStorage.storeObject('userinfo',$scope.loginData); 
     AuthFactory.login($scope.loginData); 
     $scope.closeLogin(); 
    }; 

    $scope.logout = function() { 
     AuthFactory.logout(); 
     $rootScope.currentUser = false; 
     $rootScope.username = ''; 
     $rootScope.admin = false; 
     $rootScope.isVerified = false; 
     $rootScope.uid = ''; 
     $state.go("app"); 
    }; 

    // On successful login 
    $rootScope.$on('login:Successful', function() { 
     $rootScope.currentUser = AuthFactory.isAuthenticated(); 
     $rootScope.username = AuthFactory.getUsername(); 
     $rootScope.admin = AuthFactory.isAdmin(); 
     $rootScope.uid = AuthFactory.uid(); 
     $rootScope.isVerified = AuthFactory.isVerified(); 
    }); 

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

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

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

    // Perform the login action when the user submits the login form 
    $scope.doRegister = function() { 
     console.log('Doing registration', $scope.registration); 
     $scope.loginData.username = $scope.registration.username; 
     $scope.loginData.password = $scope.registration.password; 

     AuthFactory.register($scope.registration); 
     // Simulate a login delay. Remove this and replace with your login 
     // code if using a login system 
     $timeout(function() { 
      $scope.closeRegister(); 
     }, 1000); 
    }; 

    // On successful registration 
    $rootScope.$on('registration:Successful', function() { 
     $rootScope.currentUser = AuthFactory.isAuthenticated(); 
     $rootScope.username = AuthFactory.getUsername(); 
     $rootScope.admin = AuthFactory.isAdmin(); 
     $rootScope.uid = AuthFactory.uid(); 
     $rootScope.isVerified = AuthFactory.isVerified(); 
    }); 

    $scope.toggleLeft = function() { 
     $ionicSideMenuDelegate.toggleLeft(); 
     }; 
}]); 

回答

0

您需要在角度應用程序初始化中注入ui-router模塊。

angular.module('watchHoursApp', ['ionic','ui.router'])

+0

誰幹的,沒有工作......沒有進展 –

+0

你在控制檯現在得到任何錯誤? –

+0

離子默認包括...這是我的第二個離子項目...有些東西是缺少的,很難找出..現在浪費了近1小時 –

相關問題