2015-10-19 205 views
0

我無法理解爲什麼ui.bootstrap依賴注入不能正常工作。當我注入依賴關係時,單個頁面中的所有內容都會消失。我在控制檯日誌中沒有收到任何錯誤。我覺得我做的一切都很好,但我需要一組新的眼睛來看看造成問題的原因。ui.bootstrap依賴注入

(function(){ 
 

 
'use strict'; 
 

 
angular.module('ghostApp',['ui.bootstrap']) 
 
    .controller('GamesCtrl',['$scope','$http',function($scope,$http){ 
 

 
    \t $scope.currentPage = 1; 
 
    \t $scope.pageSize = 12; 
 

 
    \t $http.get("json/games.json").success(function(data){ 
 
    \t \t $scope.games = data; 
 
    \t }); 
 

 

 
    }]); 
 

 
})();
<!doctype html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <title></title> 
 
    <meta name="description" content=""> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> 
 
    <!-- build:css(.) styles/vendor.css --> 
 
    <!-- bower:css --> 
 
    <link rel="stylesheet" href="bower_components/bootstrap/dist/css/bootstrap.css" /> 
 
    <!-- endbower --> 
 
    <!-- endbuild --> 
 
    <!-- build:css(.tmp) styles/main.css --> 
 
    <link rel="stylesheet" href="styles/main.css"> 
 
    <!-- endbuild --> 
 
    </head> 
 
    <body ng-app="ghostApp"> 
 
    <!--[if lte IE 8]> 
 
     <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> 
 
    <![endif]--> 
 

 
    <!-- Add your site or application content here --> 
 
    <nav class="navbar navbar-default navbar-fixed-top"> 
 
     <div class="container"> 
 
      <!-- Brand and toggle get grouped for better mobile display --> 
 
      <div class="navbar-header page-scroll"> 
 
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
 
        <span class="sr-only">Toggle navigation</span> 
 
        <span class="icon-bar"></span> 
 
        <span class="icon-bar"></span> 
 
        <span class="icon-bar"></span> 
 
       </button> 
 
       <img class="navbar-brand" src="images/ghost.png"></a> 
 
      </div> 
 
      <!-- Collect the nav links, forms, and other content for toggling --> 
 
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
 
       <ul class="nav navbar-nav navbar-right"> 
 
        <li class="hidden"> 
 
         <a href="#page-top"></a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/home/">Home</a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/events/">Events</a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/games/">Games</a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/media/">Media</a> 
 
        </li>     
 
        <li class="page-scroll text-center"> 
 
         <a href="#/about/">About</a> 
 
        </li> 
 
       </ul> 
 
      </div> 
 
      <!-- /.navbar-collapse --> 
 
     </div> 
 
     <!-- /.container-fluid --> 
 
    </nav> 
 

 

 
    <div class="container-fluid margin-content"> 
 
    <div ng-view=""></div> 
 
    </div> 
 

 

 
    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID --> 
 
    <script> 
 
     !function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){ 
 
     (A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g), 
 
     r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r) 
 
     }(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); 
 

 
     ga('create', 'UA-XXXXX-X'); 
 
     ga('send', 'pageview'); 
 
    </script> 
 

 
    <!-- build:js(.) scripts/vendor.js --> 
 
    <!-- bower:js --> 
 
    <script src="bower_components/jquery/dist/jquery.js"></script> 
 
    <script src="bower_components/angular/angular.js"></script> 
 
    <script src="bower_components/bootstrap/dist/js/bootstrap.js"></script> 
 
    <script src="bower_components/angular-route/angular-route.js"></script> 
 
    <script src="bower_components/angular-bootstrap/ui-bootstrap-tpls.js"></script> 
 
    <!-- endbower --> 
 
    <!-- endbuild --> 
 

 
     <!-- build:js({.tmp,app}) scripts/scripts.js --> 
 
     <script src="scripts/app.js"></script> 
 
     <script src="scripts/controllers/main.js"></script> 
 
     <script src="scripts/controllers/about.js"></script> 
 
     <script src="scripts/controllers/games.js"></script> 
 
     <!-- endbuild --> 
 
</body> 
 
</html> 
 

 

 
<!---- games.html START ---> 
 

 
<input type="text" ng-model="searchGame" placeholder="Search for Game" > 
 
<div class = "row" ng-controller = "GamesCtrl"> 
 

 

 
\t <div class = "col-xs-6 col-md-3 well" ng-repeat = "game in games | filter: searchGame"> 
 
\t \t <a href = "#" class = "thumbnail"> 
 
\t \t \t <img style="height:100px"ng-src = "{{game.image}}" alt="{{game.name}}"> 
 
\t \t </a> 
 
\t \t <div class = "text-center">{{game.name}}</div> 
 
\t </div> 
 
\t 
 
\t <div class = "col-xs-12"> 
 
\t \t <pagination class = "pagination" total-items="games.length" ng-model="currentPage" items-per-page="pageSize"></pagination> 
 
\t </div> 
 
\t 
 

 
</div> 
 

 
<!---- games.html END --->

回答

0

只是刪除jQuery和bootstrap.js包括來自CDN的依賴沒有看到這個問題。

(function(){ 
 

 
'use strict'; 
 

 
angular.module('ghostApp',['ui.bootstrap']) 
 
    .controller('GamesCtrl',['$scope','$http',function($scope,$http){ 
 

 
    \t $scope.currentPage = 1; 
 
    \t $scope.pageSize = 12; 
 

 
    \t $http.get("json/games.json").success(function(data){ 
 
    \t \t $scope.games = data; 
 
    \t }); 
 

 

 
    }]); 
 

 
})();
<!doctype html> 
 
<html> 
 
    <head> 
 
    <meta charset="utf-8"> 
 
    <title></title> 
 
    <meta name="description" content=""> 
 
    <meta name="viewport" content="width=device-width"> 
 
    <!-- Place favicon.ico and apple-touch-icon.png in the root directory --> 
 
    <!-- build:css(.) styles/vendor.css --> 
 
    <!-- bower:css --> 
 
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css" /> 
 
    <!-- endbower --> 
 
    <!-- endbuild --> 
 
    <!-- build:css(.tmp) styles/main.css --> 
 
    <link rel="stylesheet" href="styles/main.css"> 
 
    <!-- endbuild --> 
 
    </head> 
 
    <body ng-app="ghostApp"> 
 
    <!--[if lte IE 8]> 
 
     <p class="browsehappy">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> to improve your experience.</p> 
 
    <![endif]--> 
 

 
    <!-- Add your site or application content here --> 
 
    <nav class="navbar navbar-default navbar-fixed-top"> 
 
     <div class="container"> 
 
      <!-- Brand and toggle get grouped for better mobile display --> 
 
      <div class="navbar-header page-scroll"> 
 
       <button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#bs-example-navbar-collapse-1"> 
 
        <span class="sr-only">Toggle navigation</span> 
 
        <span class="icon-bar"></span> 
 
        <span class="icon-bar"></span> 
 
        <span class="icon-bar"></span> 
 
       </button> 
 
       <img class="navbar-brand" src="images/ghost.png"></a> 
 
      </div> 
 
      <!-- Collect the nav links, forms, and other content for toggling --> 
 
      <div class="collapse navbar-collapse" id="bs-example-navbar-collapse-1"> 
 
       <ul class="nav navbar-nav navbar-right"> 
 
        <li class="hidden"> 
 
         <a href="#page-top"></a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/home/">Home</a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/events/">Events</a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/games/">Games</a> 
 
        </li> 
 
        <li class="page-scroll text-center"> 
 
         <a href="#/media/">Media</a> 
 
        </li>     
 
        <li class="page-scroll text-center"> 
 
         <a href="#/about/">About</a> 
 
        </li> 
 
       </ul> 
 
      </div> 
 
      <!-- /.navbar-collapse --> 
 
     </div> 
 
     <!-- /.container-fluid --> 
 
    </nav> 
 

 

 
    <div class="container-fluid margin-content"> 
 
    <div ng-view=""></div> 
 
    </div> 
 

 

 
    <!-- Google Analytics: change UA-XXXXX-X to be your site's ID --> 
 
    <script> 
 
     !function(A,n,g,u,l,a,r){A.GoogleAnalyticsObject=l,A[l]=A[l]||function(){ 
 
     (A[l].q=A[l].q||[]).push(arguments)},A[l].l=+new Date,a=n.createElement(g), 
 
     r=n.getElementsByTagName(g)[0],a.src=u,r.parentNode.insertBefore(a,r) 
 
     }(window,document,'script','https://www.google-analytics.com/analytics.js','ga'); 
 

 
     ga('create', 'UA-XXXXX-X'); 
 
     ga('send', 'pageview'); 
 
    </script> 
 

 
    <!-- build:js(.) scripts/vendor.js --> 
 
    <!-- bower:js --> 
 
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> 
 
    <script src="https://cdnjs.cloudflare.com/ajax/libs/angular-ui-bootstrap/0.14.2/ui-bootstrap-tpls.js"></script> 
 
    <!-- endbower --> 
 
    <!-- endbuild --> 
 

 
     <!-- build:js({.tmp,app}) scripts/scripts.js --> 
 
     <script src="scripts/app.js"></script> 
 
     <script src="scripts/controllers/main.js"></script> 
 
     <script src="scripts/controllers/about.js"></script> 
 
     <script src="scripts/controllers/games.js"></script> 
 
     <!-- endbuild --> 
 
</body> 
 
</html> 
 

 

 
<!---- games.html START ---> 
 

 
<input type="text" ng-model="searchGame" placeholder="Search for Game" > 
 
<div class = "row" ng-controller="GamesCtrl"> 
 

 

 
\t <div class = "col-xs-6 col-md-3 well" ng-repeat = "game in games | filter: searchGame"> 
 
\t \t <a href = "#" class = "thumbnail"> 
 
\t \t \t <img style="height:100px" ng-src="{{game.image}}" alt="{{game.name}}"> 
 
\t \t </a> 
 
\t \t <div class = "text-center">{{game.name}}</div> 
 
\t </div> 
 
\t 
 
\t <div class = "col-xs-12"> 
 
\t \t <pagination class = "pagination" total-items="games.length" ng-model="currentPage" items-per-page="pageSize"></pagination> 
 
\t </div> 
 
\t 
 

 
</div> 
 

 
<!---- games.html END --->