为什么在注入所有依赖项后,我一直收到$ [injector:modulerr]未捕获的错误?

时间:2017-07-08 07:28:14

标签: angularjs

下面是我的index.html页面,它有两个按钮,链接到2个不同的视图,我打算使用角度路由显示。

以下是我的

HTML

<!DOCTYPE html>
<html>
<head>
    <title>PR_APP</title>
    <link rel="stylesheet" href="css/style.css">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular.min.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular-route.js"></script>
    <script src="js/main.js"></script>
    <script src="js/services.js"></script>
</head>
<body ng-app="new_pr_app">
    <h2>Please select an option</h2><br>
    <div ng-controller="view_controller">
        <button id="view_details" ng-click="view()">View Details</button>
    </div>

    <div ng-controller="update_controller">
        <button id="update_details" ng-click="update()">Update Details</button>
    </div>

    <div ng-view>

    </div>

</body>

下面是我的main.js文件,其中包含上述控制器和角度路由逻辑。

main.js

var app = angular.module('new_pr_app', ['ngRoute']);

app.config('$routeProvider','$locationProvider', function($routeProvider,$locationProvider){
        $routeProvider.when("/update",
        {
            templateUrl:"update.html",
            controller: "update_controller"
        })
        .when("/view", 
        {
            templateUrl: "view.html",
            controller: "view_controller"
        });
});

app.controller("view_controller",function($scope, $location, http_factory){
$scope.view = function(){
    $location.path("/view");
}
    $scope.result =[];
    http_factory.get_request().then(function(response){
        $scope.result = response.data;    
    });
});

app.controller("update_controller",function($scope, $location, http_factory){
$scope.update_details = function(){
    $location.path("/update");
}
    $scope.names = [];
    http_factory.get_request().then(function(response){
        $scope.names = response.data;
    });
});

我有另一个名为services.js的文件,它有一个服务工厂,可以使用http get从json文件中获取详细信息。

我唯一的问题似乎是在上面的main.js中,每次index.html加载时都会出现错误

  

angular.js:88未捕获错误:[$ injector:modulerr]

2 个答案:

答案 0 :(得分:1)

您的配置错误。传入一个字符串作为第一个(和第二个参数),而Bitmap targetBitmap = new Bitmap(pictureBox3.ClientSize.Width, pictureBox3.ClientSize.Height); pictureBox3.DrawToBitmap(targetBitmap, pictureBox3.ClientRectangle); 函数需要传入一个函数(或一个数组)。

在你的代码中,你只是忘了将参数包装在一个数组中。以下是它的外观:

.config(..)

请注意包含内容的app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider){ $routeProvider.when("/update", { templateUrl:"update.html", controller: "update_controller" }) .when("/view", { templateUrl: "view.html", controller: "view_controller" }); }]); [

答案 1 :(得分:0)

您可以查看以下代码。

<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.6.5/angular-route.js"></script>
<body ng-app="new_pr_app">



  <h2>Please select an option</h2><br>
    <div ng-controller="view_controller">
        <button id="view_details" ng-click="view()">View Details</button>
    </div>

    <div ng-controller="update_controller">
        <button id="update_details" ng-click="update_details()">Update Details</button>
    </div>

    <div ng-view>

    </div>

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

app.config(['$routeProvider','$locationProvider', function($routeProvider,$locationProvider){
        $routeProvider.when("/update",
        {
            template:"update template"
           // controller: "update_controller"
        })
        .when("/view", 
        {
            template: "view template"
           // controller: "view_controller"
        });
}]);

app.controller("view_controller",function($scope, $location){
$scope.view = function(){
    $location.path("/view");
}
});

app.controller("update_controller",function($scope, $location){
$scope.update_details = function(){
    $location.path("/update");
}
    
});
</script>

</body>
</html>