0

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?

2 Answers 2

4

Just add the factory in your controller.

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

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

5 Comments

Error: [$injector:unpr] Unknown provider: $resourceProvider <- $resource <- Phone
Did you load the ngResource script and added it as an dependency in your app?
I believe this answer is the right approach. It is not obvious to me from the question if the factory is created on the same module that the controller is created on. Assuming that 'services' is the name of the module, then replace app with services.
@PriyaBhatt please read this
thanks for the link. it is bit confusing to use angular with require. i am using following link to integrate angular with require but i dont know how to use services.factory with following link github.com/StarterSquad/startersquad.github.com/tree/master/…
1

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

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.