2015-05-30 43 views
1

我看了下面的問題,一直沒能找到有效的解決方案,因此我發佈了另一個問題。使用離子 - 無法正確加載Firebase - 錯誤:無法使用模塊'firebase'

Ionic + firebase, error Module 'firebase' is not available

Firebase, AngularFire Error: Module firebase is not available

Angularfire 'Firebase' is not defined

我非常初學者,這是使用火力地堡我的第一離子的應用程序。我只是試圖讓Firebase加載正確。我已經包含在我的index.html以下的CDN:

HTML:

app.js:

angular.module('starter', ['ionic', 'firebase', 'starter.controllers', 'starter.services']) 



.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 && window.cordova.plugins.Keyboard) { 
     cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true); 
    } 
    if (window.StatusBar) { 
     // org.apache.cordova.statusbar required 
     StatusBar.styleLightContent(); 
    } 


    }); 
}) 

.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 

    // setup an abstract state for the tabs directive 
    .state('tab', { 
    url: "/tab", 
    abstract: true, 
    templateUrl: "templates/tabs.html" 
    }) 

    // Each tab has its own nav history stack: 

    .state('tab.login', { 
    url: '/login', 
    views: { 
     'tab-login': { 
     templateUrl: 'templates/tab-login.html', 
     controller: 'LoginCtrl' 
     } 
    } 
    }) 

    .state('tab.new', { 
    url: '/new', 
    views: { 
     'tab-new': { 
     templateUrl: 'templates/tab-new.html', 
     controller: 'NewCtrl' 
     } 
    } 
    }) 

    .state('tab.home', { 
     url: '/home', 
     views: { 
     'tab-home': { 
      templateUrl: 'templates/tab-home.html', 
      controller: 'HomeCtrl' 
     } 
     } 
    }) 


    .state('tab.profile', { 
    url: '/profile', 
    views: { 
     'tab-profile': { 
     templateUrl: 'templates/tab-profile.html', 
     controller: 'ProfileCtrl' 
     } 
    } 
    }); 

    // if none of the above states are matched, use this as the fallback 
    $urlRouterProvider.otherwise('/tab/home'); 

}); 

controller.js:

angular.module('starter.controllers', ['ionic', 'firebase', 'starter.services']) 


.controller('LoginCtrl', function($scope) { 


}) 

.controller('NewCtrl', function($scope) {}) 

.controller('HomeCtrl', function($scope, Chats) { 
    $scope.chats = Chats.all(); 
    $scope.remove = function(chat) { 
    Chats.remove(chat); 
    } 
}) 



.controller('ProfileCtrl', function($scope) { 
    $scope.settings = { 
    enableFriends: true 
    }; 
}); 

有了這個代碼,我得到的錯誤:

Uncaught ReferenceError: angular is not defined(anonymous function) @ angularfire.min.js:12(anonymous function) @ angularfire.min.js:12 
ionic.bundle.js:8762 Uncaught Error: [$injector:modulerr] Failed to instantiate module starter due to: 
Error: [$injector:modulerr] Failed to instantiate module firebase due to: 
Error: [$injector:nomod] Module 'firebase' is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument. 
http://errors.angularjs.org/1.3.13/$injector/nomod?p0=firebase 
    at REGEX_STRING_REGEXP (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8762:12) 
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:10466:17 
    at ensure (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10390:38) 
    at module (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10464:14) 
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12796:22 
    at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9022:20) 
    at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12780:5) 
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12797:40 
    at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9022:20) 
    at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12780:5) 
http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=firebase&p1=Error%…%3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A12780%3A5) 
    at REGEX_STRING_REGEXP (http://localhost:8100/lib/ionic/js/ionic.bundle.js:8762:12) 
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12819:15 
    at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9022:20) 
    at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12780:5) 
    at http://localhost:8100/lib/ionic/js/ionic.bundle.js:12797:40 
    at forEach (http://localhost:8100/lib/ionic/js/ionic.bundle.js:9022:20) 
    at loadModules (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12780:5) 
    at createInjector (http://localhost:8100/lib/ionic/js/ionic.bundle.js:12706:11) 
    at doBootstrap (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10144:20) 
    at bootstrap (http://localhost:8100/lib/ionic/js/ionic.bundle.js:10165:12) 
http://errors.angularjs.org/1.3.13/$injector/modulerr?p0=starter&p1=Error%3…3A%2F%2Flocalhost%3A8100%2Flib%2Fionic%2Fjs%2Fionic.bundle.js%3A10165%3A12) 

我不包括角CDN,因爲離子包括它。 我已經在firebase上創建了一個新應用,並且可以通過Firebase儀表板訪問它。

任何想法如何讓firebase正常運行?

回答

1

您需要在angularfire.min.js之前移動ionic.bundle.js,因爲在創建模塊時使用角度對象的角度fire.js &它會引發錯誤。

+1

也許Angular被包含在這個包中''script src =「lib/ionic/js/ionic.bundle.js」>',如果是這樣,他只需要將它移到他對'angularfire.min.js的引用之上' – azium

+0

@azium感謝您提出了......我剛剛更新了答案 –

相關問題