Abolfazl.D.Sh Abolfazl.D.Sh - 1 year ago 71
AngularJS Question

Defining routes for a angular module

I have a mainApp.js file and I put this code on it:

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

mainApp.config(['$routeProvider', function ($routeProvider) {
templateUrl: '/Views/Admin/index.html'

When I run my application without ROUTES section, everything is ok but when I add them to mainApp.js file I face with $injector:modulerr error in my

I try clear browser cache, check html pages to be sure about including mainApp.js file and replace my codes with these:

var mainApp = angular.module('mainApp', []).config(config);

config.$inject = ['$routeProvider'];
function config($routeProvider) {
templateUrl: '/Views/Admin/index.html'

But nothing happened and I face with that error again.

can you help me?


Answer Source

You need to inject ngRoute as a dependency, also refer the angular-router library,

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


 var mainApp = angular.module('mainApp', [ngRoute]).config(config);


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download