ng-User
ng-User

Reputation: 243

Using factory within controller in angularjs

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?

Upvotes: 0

Views: 170

Answers (1)

ms87
ms87

Reputation: 17492

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

Upvotes: 1

Related Questions