2016-02-04 101 views
0

我試圖在離子應用程序中創建簡單的導航,但我得到以下錯誤。 參數'LoginCtrl'不是一個函數,在Ionic中未定義 我做錯了什麼?參數'LoginCtrl'不是一個函數,在Ionic中得到了undefined

的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 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/angular-route.js"></script> 
    <script src="lib/angular-cookies.js"></script> 


    <script src="lib/ng-cordova/dist/ng-cordova.min.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/restService/login.js"></script> 
    </head> 
    <body ng-app="starter"> 
      <ion-nav-view></ion-nav-view> 
    </body> 
</html> 

app.js:

angular.module('starter', ['ionic', 
    'Authentication', 
    'ngCookies']) 

    .config(function($stateProvider, $urlRouterProvider) { 
    //$urlRouterProvider.otherwise('views/main') 

    $stateProvider.state('login', { 
     url: '/login', 
     controller: 'LoginCtrl', 
     templateUrl: 'views/throbber.html' 
    }) 
    }) 

    .run(['$ionicPlatform', '$rootScope', '$location', '$cookieStore', '$http', 
    function($ionicPlatform, $rootScope, $location, $cookieStore, $http) { 
    $ionicPlatform.ready(function() { 
     try { 
     if (window.cordova && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
      cordova.plugins.Keyboard.disableScroll(true); 
     } 
     if (window.StatusBar) { 
      StatusBar.styleDefault(); 
     } 
     } catch (ex) { 
     alert(ex); 
     } 
    }); 
    }]); 
    angular.module('Authentication', []); 

JS/restService/login.js:

angular.module('Authentication') 
.controller('LoginCtrl' [ 
    function() { 
    alert('test'); 
    } 
    ]); 

視圖/ throbber.html:

<div>THROBBER</div> 

回答

0

您的login.js在app.js後加載。 當您配置路由時,LoginCtrl控制器不可用於角度,因此它是「未定義」/「不是函數」。

您需要將login.js的內容移到app.js中,或者讓您的吞嚥/咕嚕聲任務運行者合併內容。

+0

它沒有幫助。我試圖將login.js複製到app.js,我試圖在啓動器模塊之前創建認證模塊,但它仍然不起作用 –

+0

@nuclearkote將認證模塊放置在啓動器模塊之前是正確的。您是否嘗試清除瀏覽器緩存或以隱身模式運行? –

相關問題