Failed to instantiate module due to


#1

I’m trying to use two different modules,i added it as dependency to my main module ,i’m getting this error…Please help !!!

Error: [$injector:modulerr] Failed to instantiate module testServices due to:
Error: [$injector:nomod] Module ‘XXXX’ is not available! You either misspelled the module name or forgot to load it. If registering a module ensure that you specify the dependencies as the second argument.


#2

The two most common reasons imo is that you forgot to include the <script> tag for your file in index.html (make sure your path is correct!), or that you’re adding the wrong module. If neither is the case a codepen would help.


#3

yeah i forgot to add script tag…After adding i defined a controller function in the new file as below

angular.module(‘TestCtrl’, [])

.controller(‘TestCtrl’, [’$scope’, function ($scope) {

console.log(“hello!”);

}])

after that i tried to access it from my html template as

ion-view view-title=“Testing Space”>
ion-content>
h1>Test

div ng-controller=“TestCtrl”>
/ion-content>
/ion-view>

I’m now getting this error

Error: [ng:areq] Argument ‘TestCtrl’ is not a function, got undefined


#4

You now also created a new module called TestCtrl, did you use ng-app="TestCtrl"? Alternatively added TestCtrl as a dependency to your app.


#5

i added it as a dependency to my main module


#6

Could you put together a codepen to illustrate what you have? It’s hard to guess at the problem when we can only see a limited piece of the code.


#7

#8

Pen may not give any output , libraries are not inserted in index.html properly.I want you to check the dependency part.I was strugling with this since many days writing all js in one file .Thank you


#9

You never did add the dependency to your new module. On line 18, you’ll need to add 'TestCtrl', like so:

(I cleaned it up a bit to get the output, but line 18 is all you need to care about)


#10

Thanks sir, I think i’ve been confused little bit.
Thank you :smile: