Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have simple module with controller and factory. I want to use factory within my controller. So I should add the name of factory within my function() of controller. Adding this, so my controller doesnt work anymore (blank page, no errors)

var app = angular.module('main', ['ngAnimate'])
app.factory('Socket', function($scope) { ... });

My controller works if:

app.controller('DemoCtrl', function($scope, $http, $filter, ngTableParams, $timeout) {...});

My controller does not work if:

app.controller('DemoCtrl', function($scope, $http, $filter, ngTableParams, $timeout, Socket) {...});

Can anyone help me on this?

share|improve this question

1 Answer 1

You can't insert $scope into a service in angular, because it has no meaning in the context of services. $scope is for controllers only, so remove the $scope dependency from your service: app.factory('Socket', function() { ... });

share|improve this answer
    
Thanks for the answer. The problem was not $scope in the service. I got an error message after clearing the local storage. Socket was not defined. Problem is resolved now. –  ng-User Feb 19 '14 at 7:11

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.