Abolfazl.D.Sh Abolfazl.D.Sh - 6 months ago 45
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?



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);