1

我不确定为什么路由不起作用。View1.html 包含一个简单的网页,view2.html 也是如此。view1.html 和 view2.html 都位于名为 partials 的文件夹中,而“angular-route.js”和“angular-route.min.js”位于主文件夹中名为 node_modules 的文件夹中。我正在使用 ubuntu 14.04。

<script src="scripts/angular.min.js"></script>

<script src="/node_modules/angular-route/angular-route.js"></script>
<script src="/node_modules/angular-route/angular-route.min.js"></script>


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

    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:'nihal',city:'hyderabad'},{name:'nihal',city:'mumbai'}, {name:'john',city:'bangalore'}]
        $scope.addCustomer = function() {
            $scope.customers.push({name: newCustomer.name , city: newCustomer.city })
        }
    })


</script>
</body>
</html>
4

1 回答 1

0

您的路由语法不正确,控制器属性后缺少逗号。

于 2014-12-06T17:23:34.560 回答