0

I am trying to add a service to my app and can not see the problem. I must be missing something simple.

My App definition looks like: (lots of stuff removed in the service). The service will also be moved to a separate file once i figure out what i am doing wrong. That is why in this example it is a separate call;

var app =   angular.module('app', ['ngRoute','ngResource', 'ngAnimate', 'ui.bootstrap', 'ui.tree', 'ngMap', 'ngTagsInput', 'angular-loading-bar', 'app.controllers'
                             , 'app.directives', 'app.localization', 'app.nav', 'app.ui.ctrls', 'app.ui.directives'
                             , 'app.ui.services', 'app.ui.map', 'app.form.validation', 'app.ui.form.ctrls', 'app.ui.form.directives', 'app.tables', 'app.task'
                             , 'app.chart.ctrls', 'app.chart.directives', 'app.page.ctrls'
                             , 'virtualAssistServices'
                            ]
                      );
angular.module('app')
       .service('virtualAssistServices', ['$http', function ($http) {
                var urlBase = '/api/customers';

 }]);

if I remove virtualAssistServices from the app definition every works fine, but as soon as i add to the app module i get the error

Error: [$injector:modulerr] Failed to instantiate module app due to: [$injector:modulerr] 
Failed to instantiate module virtualAssistServices due to: [$injector:nomod] Module
'virtualAssistServices' is not available! You either misspelled the module name or 
forgot to loadit. If registering a module ensure that you specify the dependencies 
as the second argument.
 http://errors.angularjs.org/1.2.27/$injector/nomod?p0=virtualAssistServices

3 Answers 3

1

You shouldn't mention virtualAssistServices in dependencies array of your app definition, because virtualAssistServices is not a module.

You are defining the service on the app module itself. So inherently that service functionality is attached to the app.

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

Comments

0

You shouldn't list virtualAssistServices in the array when you assign the app. That's for listing modules that you depend on; you don't list your own services there.

Comments

0

Your services should go to controller instead of a module, if created as part of same module. If service is created in a different module, add the dependency in module.

app.controller('MyController', [ '$scope', 'virtualAssistServices', function($scope, virtualAssistServices) {

});

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.