最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AngularJS: call factory from controller - Stack Overflow

programmeradmin1浏览0评论

I am using following link for using requirejs with angularjs .github/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?

I am using following link for using requirejs with angularjs https://github./StarterSquad/startersquad.github./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?

Share Improve this question asked Apr 21, 2014 at 11:55 PriyaPriya 1,4814 gold badges32 silver badges56 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 4

Just add the factory in your controller.

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

});

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

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

评论列表(0)

  1. 暂无评论