1

For some reason, $firebase is undefined when I try to use it. I'm pretty new to Angular, so I'm guessing there is just some disconnect in the way I split up my files. I can get all of the code to work properly if it's in just one HTML page, but I want to split it all up, as my app will have different pages.

controllers.js

angular.module('myApp.controllers', ['firebase']).
  controller('StoryController', [function($scope, $firebase) {
    var storiesRef = new Firebase(FIREBASE_URL);
    $scope.stories = $firebase(storiesRef);
    $scope.addStory = function(e) {
      if (e.keyCode != 13) return;
      $scope.stories.$add({title: $scope.title, text: $scope.text});
      $scope.text = "";
    }
  }]);

app.js

angular.module('myApp', [
  'ngRoute',
  'myApp.filters',
  'myApp.services',
  'myApp.directives',
  'myApp.controllers'
]).
config(['$routeProvider', function($routeProvider) {
  $routeProvider.when('/stories', {templateUrl: 'partials/stories.html'});
  $routeProvider.when('/addStory', {templateUrl: 'partials/addStory.html', controller: 'StoryController'});
  $routeProvider.otherwise({redirectTo: '/'});
}]);

EDIT: Forgot to include the error.

TypeError: undefined is not a function
    at new <anonymous> (http://localhost:8000/app/js/controllers.js:8:22)
    at d (http://localhost:8000/app/lib/angular/angular.min.js:30:452)
    at Object.instantiate (http://localhost:8000/app/lib/angular/angular.min.js:31:80)
    at http://localhost:8000/app/lib/angular/angular.min.js:62:23
    at link (http://localhost:8000/app/lib/angular-route/angular-route.min.js:7:208)
    at F (http://localhost:8000/app/lib/angular/angular.min.js:49:345)
    at f (http://localhost:8000/app/lib/angular/angular.min.js:42:399)
    at http://localhost:8000/app/lib/angular/angular.min.js:42:67
    at http://localhost:8000/app/lib/angular/angular.min.js:43:299
    at z (http://localhost:8000/app/lib/angular/angular.min.js:47:23) <div ng-view="" class="ng-scope">

And I have included all the scripts I have at the end of my main template.

3
  • Is there any error output? Do you have included the necessary scripts? Commented Feb 2, 2014 at 10:50
  • Just added the error output, and yes, all the required scripts are included. Everything works just fine when it's all in one giant file. I'm just having trouble splitting it all up to make it manageable. Commented Feb 2, 2014 at 10:59
  • Is the js file minified? Commented Feb 2, 2014 at 11:02

1 Answer 1

6

You're using inline dependencies but not defining them correctly;

controller('StoryController', ['$scope', '$firebase', function($scope, $firebase) {

Read more about dependency injection here; http://docs.angularjs.org/guide/di

Sign up to request clarification or add additional context in comments.

1 Comment

I knew it was something simple! Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.