Sadeep Sadeep - 1 year ago 187
AngularJS Question

Error: Can't find variable: Firebase (angularjs and angular fire)

I'm new to firebase and angularfire. In my app, I'm trying to create a new item (a teacher object) in a firebase database. I keep getting

Error: Can't find variable: Firebase

I have included following script tags in

<script type="text/javascript" src="../libs/firebase/firebase.js"></script>
<script type="text/javascript" src="../libs/angular/angularfire/angularfire.js"></script>

Then, in my
I have included

angular.module('app', ['firebase']);

My controller is:

app.controller('teacherCreateCtrl', ['$scope', '$state', 'Teacher', '$firebase', function($scope, $state, Teacher, $firebase) {
var ref = new Firebase("");
var firebaseConnection = $firebase(ref);
$scope.teacher = new Teacher();
$scope.userClickedCancel = function() {
$scope.userClickedSave = function(newTeacher) {

Code execution stops at
var ref = ...
in the controller. Appreciate any help. Thanks.

I'm using firebase 3.4.0v and angularfire 2.0.2v. Note that, my template that used this controller is embedded in
as a view.

Answer Source

You are mixing up your versions. If you are using v3.x firebase you can't use v2.x code. So instead of:

var ref = new Firebase("");

You have to do it like this:

var config = {
  apiKey: "<API_KEY>",
  authDomain: "<PROJECT_ID>",
  databaseURL: "https://<DATABASE_NAME>",
  storageBucket: "<BUCKET>",

Check out the docs for more info.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download