未被捕获的错误:没有模块

时间:2013-11-02 11:06:21

标签: angularjs

我不确定这是否重复,但我老实说似乎无法解决这个错误。我一直关注AngularJS Fundamentals In 60-ish Minutes。它很有效,直到我开始路由。我一直得到未被捕获的错误:没有模块和未被捕获的语法错误:意外令牌(当我检查chrome控制台时)。看起来路由不正常,因为在访问UsingDirectives.html后没有访问view1。

UsingDirectives.html:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html data-ng-app="demoApp">
<head>
    <title>Using angular contoller</title>
</head>
<body>
    <div>
        <!--Placeholder for views -->
        <data-ng-view></data-ng-view>
    </div>
    <script src="lib/angular.js"></script>

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

        demoApp.config(function ($routeProvider){
            $routeProvider
                .when('/',
                    {
                        controller: 'SimpleController',
                        templateUrl: 'partials/view1.html'
                    })
                .when('/view2',
                    {
                        controller: 'SimpleController',
                        templateUrl: 'partials/view2.html'
                    })
                .otherwise({redirectTo: '/'});
        });

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

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

view1.html(它位于名为partials的文件夹中):

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

    <br />
    Customer Name:<br />
    <input type="text" data-ng-model="newCustomer.name" />
    <br />
    Customer City:<br />
    <input type="text" data-ng-model="newCustomer.name" />
    <br />
    <button data-ng-click="addCustomer()"> Add Customer </button>
    <br />
    <a href = "#/view2"> view 2</a>
</div>

我正在使用eclipse

1 个答案:

答案 0 :(得分:0)

function($scope)){
                ^--- there should only be one parenthesis here