我正在尝试与Firebase一起设置AngularJS Ionic应用程序 我遵循了所有可用的指南,但Firebase对象仍未定义 这是我的index.html :(在体内)
<!-- build:js scripts/vendor.js -->
<!-- bower:js -->
<script src="bower_components/angular/angular.js"></script>
<script src="bower_components/angular-animate/angular-animate.js"></script>
<script src="bower_components/angular-sanitize/angular-sanitize.js"></script>
<script src="bower_components/angular-ui-router/release/angular-ui-router.js"></script>
<script src="bower_components/ionic/release/js/ionic.js"></script>
<script src="bower_components/ionic/release/js/ionic-angular.js"></script>
<script src="bower_components/ngCordova/dist/ng-cordova.js"></script>
<script src="bower_components/angular-dynamic-locale/src/tmhDynamicLocale.js"></script>
<script src="bower_components/angular-translate/angular-translate.js"></script>
<script src="bower_components/angular-translate-loader-static-files/angular-translate-loader-static-files.js"></script>
<script src="bower_components/localforage/dist/localforage.js"></script>
<script src="bower_components/ionic-platform-web-client/dist/ionic.io.bundle.min.js"></script>
<script src="bower_components/firebase/firebase.js"></script>
<script src="bower_components/angularfire/dist/angularfire.min.js"></script>
<!-- endbower -->
<script>
firebase.initializeApp({
apiKey: "...",
authDomain: "....firebaseapp.com",
databaseURL: "....firebaseio.com",
storageBucket: "....appspot.com"
});
</script>
<!-- endbuild -->
这是我的app.js:
'use strict';
angular.module('...', ['main', 'firebase'])
.constant('FBURL', 'https://....firebaseio.com')
.factory('Auth', function ($firebaseAuth, FBURL) {
var ref = new Firebase(FBURL);
return $firebaseAuth(ref);
});
服务 - $ firebaseAuth已成功加载,但新的Firebase新行引发Firebase未定义的异常。
谢谢!
答案 0 :(得分:1)
'use strict';
angular.module('...', ['main', 'firebase'])
.constant('FBURL', 'https://....firebaseio.com')
.factory('Auth', function ($firebaseAuth) {
var ref = firebase.database().ref();
return $firebaseAuth();
});
https://github.com/firebase/angularfire/blob/master/docs/quickstart.md#7-add-authentication