未捕获的ReferenceError:OrdersController未在最后一行定义

时间:2015-09-23 16:01:08

标签: javascript angularjs angularjs-directive angularjs-scope angularjs-ng-repeat

我得到了Uncaught ReferenceError: OrdersController在最后一行没有定义,而我已经定义了它。我错过了什么吗?

(function(){
var myApp = angular.module('myApp',['ngRoute']);

myApp.config(function($routeProvider){
    $routeProvider
    .when('/',
    {
        controller:'CustomersController',
        templateUrl:'view/customers.html'

    })
    .when('/orders/:customersId',
    {
        controller:'OrdersController',
        templateUrl:'view/orders.html'

})
.otherwise({redirectTo:'/'});
});


myApp.controller('OrdersController',
    function ($scope,$routeParams){
        var customersId = $routeParams.customersId;
        $scope.orders = null;

        function init(){
            for(var i=0;i<$scope.customers.length;i++){
                if($scope.customers[i].id === parseInt(customersId)){
                    $scope.orders = $scope.customers[i].orders;
                    break;
                }
            }
        }

        $scope.customers = [
{id:1,name:'Deepak',age:21,spent:2.1,orders:[{id:1,sku:22,product:'Nike',total:100}]},
{id:3,name:'Vikram',age:32,spent:4.2,orders:[{id:3,sku:2,product:'Prada',total:200}]}
                           ];

    });

    OrdersController.$inject = ['$scope','routeParams'];

客户控制器和相关路线工作正常。

0 个答案:

没有答案