Reputation: 4013
I am new to angularjs I am trying simple app by referring some startup tutorials When i run my app getting error as
Uncaught Error: No module: app
Here is my controller
club-controller.js
'use strict';
var app = angular.module('app');
app.controller('ClubsIndexController', ['$scope','Club','$routeParams', function($scope, Club, $routeParams){
$scope.clubs = Club.query();
}])
models.js
'use strict';
var app = angular.module('app');
app.factory('Club', function($resource){
return $resource("clubs/:id", {id: '@id'},{
index: {method: 'GET', isArray: true, responseType: 'json'}
});
})
Here is my app.js.erb
'use strict';
angular.module('app', ['ngResource'])
.config(['$routeProvider', '$locationProvider', function($routeProvider, $locationProvider){
$routeProvider
.when('/', {controller: 'ClubIndexController', templateUrl: '<%= asset_path('templates/index.html') %>'})
}]);
I couldn't understand what is happening here. Can anyone help.
Edit-1
Changed my application.js
file as
//= require jquery
//= require jquery_ujs
//= require angular
//= require ../angular/app.js
//= require_tree ../angular
But now getting error as Uncaught Error: No module: ngResource
Upvotes: 1
Views: 2443
Reputation: 446
you have add in aplication.js require angular-resource.
//= require jquery
//= require jquery_ujs
//= require angular
//= require angular-resource
//= require ../angular/app.js
//= require_tree ../angular
Upvotes: 0
Reputation: 48147
The app.js
file must be included before models.js
or club-controller.js
.
The module definition angular.module(name, [dependencies])
will create the module for you. The other usages angular.module(name)
will get the module, and expects it to have been defined with dependencies already.
Upvotes: 1