2016-07-07 193 views
1

我與angularjs嘗試,但我得到這個錯誤:未捕獲的錯誤:[$注射器: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> 

,這是我的搜索movie.js碼以下內容:

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

當我'工作,我得到一個錯誤,如在圖片enter image description here

還例如,當我我正在搜索'adphorusWork'我可以看到這個:Search finished.No matching found。它不應該是這樣的。我應該在search-movie.js中看到angular.module('adphorusWork', ['ngRoute'])

我在哪裏做錯了?

+0

您可以點擊錯誤的左側的箭頭後添加屏幕截圖? – ValLeNain

+0

如果您正在搜索'adphorus',你能找到結果嗎? –

+0

聞起來像重複。 – Knu

回答

0

確保您已添加角度和角度路線文件。

看到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); 
+1

另外,當使用全局閉包時,一個好的做法是在參數中傳遞你正在處理的對象。在你的情況下,將'angular'傳遞給全局閉包。 – ValLeNain

+0

我改變了這個 - >舊:search-movie.js新:app.js並工作。謝謝。 – eagle

+0

@ValLeNain Yepp。感謝和歡呼:) – varit05

0

包括以下內容:

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

相關問題