angularjs - Angular service which is a require js module, is not getting the injected dependencies -
angularjs - Angular service which is a require js module, is not getting the injected dependencies -
i have module 'global.services' in registered service "restservices"
(function(define, angular) { "use strict"; define(["global/services/restservices"], function(restservices) { var modulename = "global.services"; angular.module(modulename, []) .config(function(restangularprovider) { restangularprovider.setbaseurl('http://localhost:8888/src/app/data/'); restangularprovider.setrequestsuffix('.json'); }) .factory('restservices', restservices); homecoming modulename; }); }(define, angular));
and "restservice" module
(function(define, angular) { "use strict"; define(function() { var restservice = function($rootscope, restangular) { // body... homecoming { getdata: function(arg) { // body... $rootscope.$broadcast('gettingdata'); homecoming restangular.oneurl('listpanel'); } } }; homecoming restservice; }); }(define, angular));
in above service both $rootscope , restangular undefined. please tell me how inject dependencies in respect.
i found reason of $rootscope , restangular beingness undefined.
factory registration perfect when trying utilize in different module's controller injecting "global/services/restservices" instead of "global/services/services" actual services module.
previous code:
(function(define, angular) { define(['global/services/restservices'], function(restservices) { var headercontroller = function($scope, $rootscope, $translate, $location, $document, restservices) { var user_modules = window.session.getmodules(), modules = []; angular.foreach(user_modules, function(modulename) { modules.push(window.config.modules[modulename]); }); restservices.getdata('webappsdata.json').get().then(function(d) { if (d) { if (d.response) { $scope.webapps = d.response; } else { $scope.webapps = []; } } else { $scope.webapps = []; } }); $scope.title = "tumbler"; $scope.modules = modules; }; homecoming ["$scope", "$rootscope", "$translate", "$location", "$document", "restservices", headercontroller]; }) }(define, angular));
present code(working):
(function(define, angular) { define(['global/services/services'], function() { var headercontroller = function($scope, $rootscope, $translate, $location, $document, restservices) { var user_modules = window.session.getmodules(), modules = []; angular.foreach(user_modules, function(modulename) { modules.push(window.config.modules[modulename]); }); restservices.getdata('webappsdata.json').get().then(function(d) { if (d) { if (d.response) { $scope.webapps = d.response; } else { $scope.webapps = []; } } else { $scope.webapps = []; } }); $scope.title = "tumbler"; $scope.modules = modules; }; homecoming ["$scope", "$rootscope", "$translate", "$location", "$document", "restservices", headercontroller]; }) }(define, angular));
so, inject module , utilize services.
angularjs requirejs restangular
Comments
Post a Comment