locked
How to add more services in AngularJs[app.js] ? RRS feed

  • Question

  • User-1484683380 posted

    I have 3 module names 'dashboard.services1,' , 'dashboard.services2', 'dashboard.services3' .

    angular.module('dashboard.services1', [])

    .service('sublineService', function ()

     that 3 services are .js (angular) files. these files i want to add in

    app.js 

    angular.module('dashboard', ['dashboard.filters', 'dashboard.services1', 'dashboard.services2', 'dashboard.services3', 'dashboard.directives', 'dashboard.controllers']).
      config(['$routeProvider', function ($routeProvider, $routeParams) {
          // Dashboard Screens
          $routeProvider.when('/lines', { templateUrl: 'partials/lines.html', controller: 'PlantController' });
          $routeProvider.when('/lineId/:lineId/linename/:linename', { templateUrl: 'partials/line-detail.html', controller: 'LineDetailController' });
          $routeProvider.when('/subline/:lineId/:sublineId', { templateUrl: 'partials/subline-detail.html', controller: 'SublineController' });
          $routeProvider.when('/equipment/:equipmentId', { templateUrl: 'partials/equipment-detail.html', controller: 'EquipmentController' });
     $routeProvider.otherwise({ redirectTo: '/lines' });
      }]);

    but my problem is not working all these 3 files. Last one i.e 

    'dashboard.services3'

    only working and getting output from these. Other 2 files were skipped. I dono want is my problem here.

    My question is how to add more service files (i.e. module names ) / how to combine those module names into single  .js (angular) file to get all scripts files were want to work out and get my output..

    Thank you friends !

    Thursday, October 31, 2013 1:22 AM

All replies

  • User1402382751 posted

    You need to load the 3 service files after the module declaration. Each file should have the below code to register the service

    angular.module('dashboard', []).service('services1', function() {}).service('services2', function() {}).service('services3', function() {})

    This declaration makes your dashboard app register 3 services under it. You can now use services1 inside the controller by declaring it as dependency

    Saturday, November 8, 2014 1:45 AM
  • User2008642861 posted

    Hi amulsva,

    As your post, I suggest that you could use another method to achieve your goal. Here is a similar case for you to refer. Please refer to the below link.

    http://stackoverflow.com/questions/19614545/how-can-i-add-some-small-utility-functions-to-my-angularjs-application

    Hope this could be helpful to you.

    Best regards,

    Archer Wang

    Wednesday, January 14, 2015 1:51 AM