rest - Cannot add second AngularJS Service Factory -


i try add 2 services angularjs module. 1 should access employees , 1 products, unknown provider: employeeserviceprovider <- employeeservice <- bookingcontroller.

all javascript-files added html.

app/module

var coffeewatchapp = angular.module('coffeewatchapp', [     'ngroute',     'coffeewatchcontrollers',     'coffeewatchservices' ]);  //routing  var coffeewatchcontrollers = angular.module('coffeewatchcontrollers', []); var coffeewatchservices = angular.module('coffeewatchservices', []); 

employeeservice.js

var coffeewatchservices = angular.module('coffeewatchservices', ['ngresource']);  var employeeserviceurlpart = "employeeservice/"; coffeewatchservices.factory('employeeservice', ['$resource',     function($resource){         return $resource('all/', {}, {             all:     {method:'get',url:rest_baseurl+employeeserviceurlpart+"all", params:{}, isarray:true}         });     }]); 

productcontroller.js same product

var coffeewatchservices = angular.module('coffeewatchservices', ['ngresource']);  var productserviceurlpart = "productservice/"; coffeewatchservices.factory('productservice', ['$resource',     function($resource){         return $resource('all/', {}, {             all: {method:'get',url:rest_baseurl+productserviceurlpart+"all", params:{}, isarray:true}         });     }]); 

controller accessing 2 services

coffeewatchcontrollers.controller('bookingcontroller', ['$scope', 'employeeservice', 'productservice',     function ($scope, employeeservice, productservice) {         $scope.employees = employeeservice.all();         $scope.products = productservice.all(); }]); 

any appreciated; in advance.

edit: implemented employeeservice first , working great. don't understand why adding productservice kills employeeservice. thing can think of productservice somehow "overwrites" employeeservice because gets injected second.

all added js-files in index.html

<script src="js/config/app-config.js"></script> <script src="js/app.js"></script> <script src="js/controllers/dashboardcontroller.js"></script> <script src="js/controllers/statisticcontroller.js"></script> <script src="js/controllers/bookingcontroller.js"></script> <script src="js/services/employeeservice.js"></script> <script src="js/services/productservice.js"></script> 

editedit after looking @ this answer more confused why code not working, maybe other code somone spotting difference.

in both of controller files, retrieve module (remove dependency list) -

var coffeewatchservices = angular.module('coffeewatchservices'); 

add dependency ngresource here instead, while declaring in app/module -

var coffeewatchservices = angular.module('coffeewatchservices', ['ngresource']); 

your module getting re-created on second call in productcontroller, overriding previous module , service definitions.


Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

order - Notification for user in user account opencart -