Angular Js routeprovider抛出运行时错误

时间:2014-10-01 22:04:25

标签: javascript angularjs

嗨,我正在尝试学习angularjs,我遇到了错误。我正在使用Microsoft Web Developer 2010 Express。我有一个asp.net应用程序,我正在尝试构建一个spa。我有一个index.htm页面,其中包含路由逻辑和一些用作起始页的控制器逻辑

的index.htm

<!DOCTYPE html>
<html ng-app="demoApp">
<head>
    <title></title>
</head>
<body>
    <div>
        <div ng-view></div>
    </div>
    <script src="Scripts/angular.min.js"></script>

    <script>
         var demoApp = angular.module('demoApp', []);

         demoApp.config(function ($routeProvider) {
             $routeProvider
                .when('/', {
                    controller: 'SimpleController',
                    templateUrl: 'Partials/View1.htm'
                })
                .when('/view2', {
                    controller: 'SimpleController',
                    templateUrl: 'Partials/View2.htm'
                })
                .otherwise({ redirectTo: '/View1' });
         });


         demoApp.controller('SimpleController', function ($scope) {
             $scope.customers = [
                { name: 'John Smith', city: 'Phoenix' },
                { name: 'John Doe', city: 'New York' },
                { name: 'Jane Doe', city: 'San Francisco' }];

             $scope.addCustomer = function () {
                 $scope.customers.push({ name: $scope.newCustomer.name, city: $scope.newCustomer.city });
             }
         });
     </script>
</body>
</html>

视图位于名为Partials的文件夹中,并且是View1.htm

<div class="container">
    <h2>View 1</h2>
    Name:
    <input type="text" ng-model="filter.name" /> 
    <br />
    <ul>
        <li ng-repeat="cust in customers | filter:filter.name ">{{ cust.name }} - {{ cust.city }}</li>
    </ul>
    <br />
    Customer Name:<br />
    <input type="text" ng-model="newCustomer.name" />
    Customer City:<br />
    <input type="text" ng-model="newCustomer.city" />
    <br />
    <button ng-click="addCustomer()">Add Customer</button>
    <br />
    <a href="#/View2">View 2</a>
</div>

和View2.htm

<div class="container">
    <h2>View 2</h2>
    City:
    <input type="text" ng-model="city" /> 
    <br />
    <ul>
        <li ng-repeat="cust in customers | filter:name ">{{ cust.name }} - {{ cust.city }}</li>
    </ul>
    </div>

我遇到的问题是它抛出的错误表明

Microsoft JScript runtime error: [$injector:modulerr] http://errors.angularjs.org/1.2.25/$injector/modulerr?p0=demoApp&p1=%5B%24injector%3Aunpr%5D%20http%3A%2F%2Ferrors.angularjs.org%2F1.2.25%2F%24injector%2Funpr%3Fp0%3D%2524routeProvider

当我运行它时,我检查了一下是否有任何错别字,我找不到任何错字。有人可以告诉我为什么会收到此错误

0 个答案:

没有答案