KVK
KVK

Reputation: 1289

$routProvider not working in angular js

i am trying to include the view page in angularjs but it is working.

Here is my code

rootService.js

var viewCustomerModule = angular.module('viewCustomer',['ngRoute','ngResource']);

viewCustomerModule.config(function($routProvider){

      $routeProvider
      .when('/CustomerList',{
           templateUrl: 'resources/view/checker.jsp',
          controller: 'checkerController'
      })

})

viewCustomer.js

var viewCustomerModule = angular.module('viewCustomer',['ngRoute','ngResource']);
viewCustomerModule.controller('checkerController', function($scope) {
    $scope.headingTitle = "List Items";
});

masterPage.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"

    pageEncoding="ISO-8859-1"%>

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html ng-app="viewCustomer">
<head>
 <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">

    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1">

<title>Add Company</title>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.4/angular.min.js"></script>
<script src="https://code.angularjs.org/1.4.8/angular-route.js"></script>
<script src="https://code.angularjs.org/1.4.4/angular-resource.js"></script>
<script src="<c:url value="/resources/js/viewCustomer.js"/>"></script>
<script src="<c:url value="/resources/js/rootService.js"/>"></script>
</head>
<body>
<div >



<a href="#/CustomerList">ViewCustomer</a>

<div ng-view></div>


</div>
</body>
</html>

checker.jsp

<h3 ng-controller="checkerController">{{headingTitle}}</h3>

Above code i used but it is not working in browser console error is

 Error: [$injector:modulerr] http://errors.angularjs.org/1.4.4/$injector/modulerr?p0=viewCustomer&p1=%5B%24injector%3Aunpr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.4.4%2F%24injector%2Funpr%3Fp0

can any one help me to fix this

Upvotes: 1

Views: 62

Answers (2)

Ajit Soman
Ajit Soman

Reputation: 4074

Please change $routProvider to $routeProvider in your rootService.js file. So your rootService.js will look like this:

var viewCustomerModule = angular.module('viewCustomer',['ngRoute','ngResource']);

viewCustomerModule.config(function($routeProvider){

      $routeProvider
      .when('/CustomerList',{
           templateUrl: 'resources/view/checker.jsp',
          controller: 'checkerController'
      })

})

Upvotes: 1

Sajeetharan
Sajeetharan

Reputation: 222572

In viewCustomer.js you dont have to declare the module again, change it as,

   // remove this line var viewCustomerModule = angular.module('viewCustomer',['ngRoute','ngResource']);
    viewCustomerModule.controller('checkerController', function($scope) {
        $scope.headingTitle = "List Items";
    });

also change the order as,

<script src="<c:url value="/resources/js/rootService.js"/>"></script>
<script src="<c:url value="/resources/js/viewCustomer.js"/>"></script>

Upvotes: 1

Related Questions