Priya
Priya

Reputation: 1481

AngularJS: call factory from controller

I am using following link for using requirejs with angularjs https://github.com/StarterSquad/startersquad.github.com/tree/master/examples/angularjs-requirejs-2

how can i use service function which is defined in js\services\version.js

i have following code in services.

 services.factory('Phone', ['$resource',
    function($resource){
        console.log("factory");
    }]);

i want to call this factory function in controller. how to do that?

Upvotes: 0

Views: 5152

Answers (2)

Jyoti Prakash
Jyoti Prakash

Reputation: 1260

First you have to register your service in " angular.module(); "

app.controller('myController',['Phone','$scope',function(Phone,$scope){
  //your code here
}]);

Upvotes: 1

bobthedeveloper
bobthedeveloper

Reputation: 3783

Just add the factory in your controller.

app.controller('myController', function($scope, Phone){           

});

Upvotes: 4

Related Questions