$routProvider 在 angular js 中不工作

$routProvider not working in angular js

我正在尝试将视图页面包含在 angularjs 中,但它正在运行。

这是我的代码

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>

我使用了以上代码,但它在浏览器控制台中不起作用,错误是

 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

谁能帮我解决这个问题

viewCustomer.js中你不必再次声明模块,将其更改为,

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

也将顺序更改为,

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

请在您的 rootService.js 文件中将 $routProvider 更改为 $routeProvider。所以你的 rootService.js 看起来像这样:

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

viewCustomerModule.config(function($routeProvider){

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

})