0

I'm new to AngularJS and I'm learning Factory/Services. I coded this simple application to pass Fire Factory in Controller, but when I inject the Factory/Service in a controller it throws an error

home.html

<div class="home" ng-controller="HomeCtrl">
    Home <button ng-class="logut()">LogOut</button>
 {{test}}
</div>

app.js

cheers.factory('Fire',function($scope,$location,$firebaseObject){
  return  {name : 'Pawan Choudhary'};

});

cheers.controller('HomeCtrl', ['$scope','$location','Fire',function ($scope, $location,Fire) {    
    $scope.test = "working!";
}]);

It throws the following error:

enter image description here

6
  • you should define var factory = {} then creating functions and variables in factory , then return factory Commented Nov 5, 2015 at 7:35
  • 1
    @MohammadJavadSeyyedi: Nope. That's not necessary. Commented Nov 5, 2015 at 7:36
  • 1
    @OP: I don't see how the code you have in your question could cause that issue. Commented Nov 5, 2015 at 7:41
  • @andrew I'm trying to do that only. :D Commented Nov 5, 2015 at 7:42
  • Use the un-minified version of Angular for better error messages Commented Nov 5, 2015 at 7:42

2 Answers 2

1

Ok! Thanks everyone I fixed the bug by removing $scope from the factory.

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

Comments

0

The header of your factory is not correct, if you wanted to add $scope, it must look like your controller header. try this :

cheers.factory('Fire',['$scope', '$location', '$firebaseObject', function($scope,$location,$firebaseObject){

         //your code

}]);

Comments

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.