1

我正在尝试使用 angularjs,但出现此错误:未捕获错误:[$injector:modulerr]

这是我的 html 代码:

<!DOCTYPE html>
<html ng-app="adphorusWork">
<head lang="en">
    <meta charset="UTF-8">
    <title>Search Movie</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <script src="scripts/angular.min.js"></script>
    <script src="scripts/angular-route.min.js"></script>
    <script src="scripts/jquery-1.9.1.min.js"></script>
    <script src="app/search-movie.js"></script>
</head>
<body ng-controller="searchMovieController">
    <div class="navbar navbar-default navbar-fixed-top" style="margin-top: 20px;">
        <div class="container-fluid">
            <ul>
                <li>
                    <a href="http://www.omdbapi.com/">OMDb Api</a>
                </li>
            </ul>
        </div>
    </div>
    <div class="container" style="margin-top: 50px;">
        <div class="bs-docs-section" id="">
            <div class="row">
                <div class="col-lg-12">
                    <div class="page-header">
                        <h2><a href="https://github.com/Cakmakk">My Github</a></h2>
                    </div>
                    <div class="bs-component">
                        <form class="well form-search" id="search-movie" onsubmit="return false;">
                            <fieldset>
                                <legend>Search Movie</legend>
                            </fieldset>
                            <div>
                                <label class="control-label" for="movie-name">Movie Name : </label>
                                <input type="text" id="movie-name" class="input-small" style="margin-left: 10px;">
                                <button id="btn-search-movie" type="button" class="btn-sm btn-primary" style="margin-left: 10px;" ng-click="searchMovie()">
                                    <span class="glyphicon glyphicon-search"> Search</span>
                                </button>
                            </div>
                        </form>
                    </div>
                </div>
            </div>
        </div>
    </div>
</body>
</html>

这是我的 search-movie.js 代码,如下所示:

(function () {
    'use strict';
    angular.module('adphorusWork', ['ngRoute'])
       .controller('searchMovieController',
       ['$scope','$route',
       function ($scope,$route) {
           $scope.searchMovie = function () {
               alert("come")
           }
       }]);
})();

当我工作时,我收到了图片中的错误在此处输入图像描述

也例如当我搜索“adphorusWork”时,我可以看到:搜索完成。未找到匹配项。不应该是这样的。我应该angular.module('adphorusWork', ['ngRoute'])在 search-movie.js 中看到

我在哪里做错了?

4

2 回答 2

0

确保您已添加 angular 和 angular-route 文件。

见 pluker:https ://plnkr.co/edit/xZFrNepOa5wsbM0lMUbV?p=preview

它对我来说工作正常,没有错误。

(function (angular) {
'use strict';
angular.module('adphorusWork', ['ngRoute'])
   .controller('searchMovieController',
   ['$scope','$route',
   function ($scope,$route) {
       $scope.searchMovie = function () {
           alert("come")
       }
   }]);
})(angular);
于 2016-07-07T11:40:39.103 回答
0

包括以下这些:

var app = angular.module("myApp", ["ngRoute"]);

于 2017-07-19T23:50:58.863 回答