本文介绍了为什么我收到“错误:[$喷油器:modulerr] http://errors.angularjs.org/1.2.21/$injector/modulerr”的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<html ng-app="demoapp">
<head>
    <script type="text/javascript" src="../angular.min.js"></script>
    <script type="text/javascript">
        var demoapp = angular.module('demoapp', []);

        demoapp.controller('SimpleController',function ($scope){
            $scope.customer = [
                {name: "Deepak" , city: "Bhubaneswar"},
                {name: "Sivaji" , city: "Banglore"}
            ];
            $scope.addCustomer = function($scope){
                $scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
            }
        }); 

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

    </script>   
</head>
<body>
    <div ng-view=""></div>
</body>

可以在任何请建议我去什么错在这里?为什么我收到错误。我是新手的角度,请帮助。我认为有一些问题与配置部分。但我不能够调试它。

Could any please suggest me what going wrong here?Why I am getting error. I am newbie to Angular please help. I think there is some issue with the config portion. But I am not able to debug it.

推荐答案

添加角航线脚本

<script src="//cdnjs.cloudflare.com/ajax/libs/angular.js/1.2.20/angular-route.min.js"></script>

添加ngRoute作为依赖

Add ngRoute as dependency

var demoapp = angular.module('demoapp', ["ngRoute"]);

您应该定义控制器这样的。

You should define controller like this.

demoapp.controller('SimpleController',["$scope", function ($scope){
    $scope.customer = [
         {name: "Deepak" , city: "Bhubaneswar"},
         {name: "Sivaji" , city: "Banglore"}
    ];
        $scope.addCustomer = function($scope){
            $scope.customer.push({ name: $scope.newCustomer.name ,city: $scope.newCustomer.city});
        }
}]); 

这篇关于为什么我收到“错误:[$喷油器:modulerr] http://errors.angularjs.org/1.2.21/$injector/modulerr”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-27 18:19