Solved

Help with AngularJS - Error: [$injector:nomod] Module 'app' is not available!

Posted on 2015-01-13
3
1,489 Views
Last Modified: 2015-02-03
Any idea why this error occurs?
Error: [$injector:nomod] Module 'app' is not available!


http://jsfiddle.net/JElster/me5Lcvsq/1/



<div ng-app="app" ng-controller="ctrl">
  {{catalog}}
</div>

<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.0/angular.min.js"></script>




var app = angular.module('app', ['jsonService']);

angular.module('jsonService', ['ngResource'])
.factory('JsonService', function($resource) {
  return $resource('https://s3-us-west-2.amazonaws.com/s.cdpn.io/93930/catalog.json');
});

app.controller('ctrl', function($scope, JsonService){
  JsonService.get(function(data){
    $scope.catalog = data;
  });
});
0
Comment
Question by:JElster
  • 2
3 Comments
 
LVL 30

Accepted Solution

by:
Alexandre Simões earned 500 total points
ID: 40546549
I'm not sure if you can put the ng-app and the ng-controller in the same DOM element...
I would say that you can't.

Try something like:
<div ng-app="app">
<div ng-controller="ctrl">
  {{catalog}}
</div>
</div>

Open in new window

I don't know what's your reason to have it like you have but usually the ng-app goes in the broadest element possible... the <html> or the <body> for instance.
0
 
LVL 1

Author Comment

by:JElster
ID: 40546585
Still get
 Uncaught Error: [$injector:modulerr] Failed to instantiate module app due to:
Error: [$injector:nomod] Module 'app' 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.
0
 
LVL 30

Expert Comment

by:Alexandre Simões
ID: 40546622
Where are you adding your javascript that contains the module?
It should be added after the angularjs javascript file reference.

Do you have any other javascript errors in the console?
Disn't you forget to add the reference to the javascript file that contains the code (happens very often)?
0

Featured Post

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

In Part 1 (http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/A_7849-Hex-Maze.html) we covered the hexagonal maze basics -- how the cells are represented in a JavaScript array and how the maze is displayed.  In this part, we'…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now