0

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?

1 Answer 1

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() { ... });

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

1 Comment

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.

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.