2016-07-14 101 views
0

我有一個空白頁面,我嘗試使用angularjs來學習Angular。空白頁angularjs

我沒有錯誤控制檯,只是一個空白頁

 <!DOCTYPE html> 
<html lang="fr"> 
    <head> 
     <meta charset="utf-8"> 
     <meta http-equiv="X-UA-Compatible" content="IE=edge"> 
     <meta name="viewport" content="width=device-width, initial-scale=1"> 
     <title>Parc Automobile</title> 
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" integrity="sha384-1q8mTJOASx8j1Au+a5WDVnPi2lkFfwwEAa8hDDdjZlpLegxhjVME1fgjWPGmkzs7" crossorigin="anonymous"> 
     <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.7/angular.min.js" type="text/javascript"></script> 
     <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js"></script> 
     <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js" integrity="sha384-0mSbJDEHialfmuBBQP6A4Qrprq5OVfW37PRR3j5ELqxss1yVqOtnepnHVP9aJ7xS" crossorigin="anonymous"></script> 
     <link rel="stylesheet" href="style.css" media="screen" charset="utf-8"> 
     <script src="app/app.js"/> 
    </head> 
    <body ng-app="parcAutoApp" ng-controller="autoCtrl"> 
     <div class="container-fluid"> 
      <div class="row section"> 
       <div class="col-md-4 col-md-offset-4"> 
        <form> 
         <div class="form-group"> 
          <label for="no_vehicule">N° du véhicule</label> 
          <input type="text" class="form-control" id="no_vehicule" placeholder="N° du véhicule" ng-model="vehicule.no"> 
         </div> 
         <div class="form-group"> 
          <label for="marque_vehicule">Marque du véhicule</label> 
          <input type="text" class="form-control" id="marque_vehicule" placeholder="Marque du véhicule" ng-model="vehicule.marque"> 
         </div> 
         <div class="form-group"> 
          <label for="modele_vehicule">Modèle du véhicule</label> 
          <input type="text" class="form-control" id="modele_vehicule" placeholder="Modèle du véhicule" ng-model="vehicule.modele"> 
         </div> 
         <div class="form-group"> 
          <label for="immat_vehicule">Immatriculation du véhicule</label> 
          <input type="text" class="form-control" id="immat_vehicule" placeholder="Immatriculation du véhicule" ng-model="vehicule.immat"> 
         </div> 
         <div class="form-group"> 
          <label for="km_vehicule">Kilométrage du véhicule</label> 
          <div class="input-group"> 
           <input type="text" class="form-control" id="km_vehicule" placeholder="Kilométrage du véhicule" ng-model="vehicule.kms"> 
           <div class="input-group-addon">km</div> 
          </div> 
         </div> 
         <button type="submit" class="btn btn-primary" ng-click="addAuto(vehicule)">Ajouter un véhicule</button> 
        </form> 
       </div> 
      </div> 
      <div class="row section"> 
       <div class="col-md-4 col-md-offset-4"> 
        <div class="table-responsive"> 
         <table class="table table-hover"> 
          <thead> 
           <tr> 
            <th>Numéro</th> 
            <th>Marque</th> 
            <th>Modèle</th> 
            <th>Immatriculation</th> 
            <th>Kilométrage</th> 
           </tr> 
          </thead> 
          <tbody> 
           <tr ng-repeat="vehicule in vehicules"> 
            <td>{{ vehicule.no }}</td> 
            <td>{{ vehicule.marque }}</td> 
            <td>{{ vehicule.modele }}</td> 
            <td>{{ vehicule.immat }}</td> 
            <td>{{ vehicule.kms }}</td> 
           </tr> 
          </tbody> 
         </table> 
        </div> 
       </div> 
      </div> 
     </div> 
    </body> 
</html> 

angular.module('parcAutoApp', []); 
.factory('vehiculesFactory', [function() { 
return { 
    vehicules: [], 
    addToVehicules: function(vehicule) { 
     this.vehicules.push(vehicule); 
    }, 
    getVehicules: function() { 
     return this.vehicules; 
    }, 
    getNbVehicules: function() { 
     return this.vehicules.length; 
    }, 
}; 
}]) 

.controller('autoCtrl', function($scope, vehiculesFactory) { 
$scope.addAuto = function(vehicule) { 
    vehiculesFactory.addToVehicules(vehicule); 
}; 

$scope.vehicules = vehiculesFactory.getVehicules(); 

}); 

是一個什麼這個blankpage的原因嗎?

預先感謝

+0

你不進口角腳本中任何 – Karim

+0

這不是在我的例子,但我,靜靜的,我通過交換的jquery.js有一個空白頁面 –

+0

,並嘗試在頭angular.js庫。即使你得到空白頁打開控制檯,看看你是否有任何錯誤。 – NNR

回答

0
<div class="container-fluid" ng-controller="autoCtrl"> 
... 
</div > 
+0

我更新了我的代碼,但我仍然有空白頁面 –

+0

包括控制器是必要的,但是vehicules:[]是空的嗎?如果是這樣的話,請添加一些數據 – npr

+2

儘管此代碼可能有助於解決問題,但 提供了關於_why_和/或_how_的其他上下文,回答此問題將顯着提高其長期價值。請[編輯]你的答案,添加一些 的解釋。 –

0
  1. 首先進口角模塊,它缺少
  2. 控制器(autoCtrl)附加到在需要它的特定元素。
+0

我添加了控制器,但仍然空白。 –