I am trying to make a service call from angular js. I downloaded the angular project. And inside view1.js wrote the following code to call the service:
'use strict'; angular.module('myApp.view1', ['ngRoute','ngResource']) .config(['$routeProvider', function($routeProvider) { $routeProvider.when('/view1', { templateUrl: 'view1/view1.html', controller: 'View1Ctrl' }); }]) .factory('Entry', ['$resource',function($resource) { return $resource('http://localhost:8000/emp/');
Here is index.html , where I included the necessary scripts:
<!DOCTYPE html> <html lang="en" ng-app="myApp" class="no-js"> <head> <meta charset="utf-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <title>My AngularJS App</title> <meta name="description" content=""> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="bower_components/html5-boilerplate/css/normalize.css"> <link rel="stylesheet" href="bower_components/html5-boilerplate/css/main.css"> <link rel="stylesheet" href="app.css"> <script src="bower_components/html5-boilerplate/js/vendor/modernizr-2.6.2.min.js"></script> </head> <body> <ul class="menu"> <li><a href="#/view1">view1</a></li> <li><a href="#/view2">view2</a></li> </ul> <div ng-view></div> <div>Angular seed app: v<span app-version></span></div> <script src="bower_components/angular/angular.js"></script> <script src="bower_components/angular-route/angular-route.js"></script> <script src="angular-resource.js"></script> <script src="app.js"></script> <script src="view1/view1.js"></script> <script src="view2/view2.js"></script> <script src="components/version/version.js"></script> <script src="components/version/version-directive.js"></script> <script src="components/version/interpolate-filter.js"></script> </body> </html>
But when the application starts, the following error is displayed in the browser:
Uncaught Error: [$injector:modulerr] Failed to instantiate module myApp due to: Error: [$injector:modulerr] Failed to instantiate module myApp.view1 due to: Error: [$injector:modulerr] Failed to instantiate module ngResource due to: Error: [$injector:nomod] Module 'ngResource' 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.
javascript angularjs ngresource
iJade
source share