0

我不确定这是否是重复的,但老实说我似乎无法解决这个错误。我一直在关注AngularJS Fundamentals In 60-ish Minutes。在我开始路由之前它运行良好。我不断收到未捕获的错误:没有模块和未捕获的语法错误:意外令牌(当我检查 chrome 控制台时)。由于在我访问 UsingDirectives.html 后未访问 view1,因此路由似乎无法正常工作。

使用Directives.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>

我正在使用日食

4

1 回答 1

0
function($scope)){
                ^--- there should only be one parenthesis here
于 2013-11-02T11:44:16.673 回答