2017-09-25 104 views
-4

这是我的代码为角js和html.Please帮我关于this.Why它不工作与文件如果任何错误的语法在HTML文件或角文件? 我想做一个订单表,我正在使用角度js方法,每次当我在浏览器上运行时,Angular代码不工作,并且添加按钮对我来说也不起作用,用于添加更多实体为了。为什么我的Angular js代码不工作?

angular.module('Commande', []) 
 
    .controller('commandeController', ['$scope', function($scope) { 
 

 
     $scope.articles = [ 
 
       { id: 1, reference: 123, titre: "MSI GTX 980ti", prixUnitaire: 666.63, quantite: 0, montantHT: 666.63, montantTTC: 799.95 }, 
 
       { id: 2, reference: 456, titre: "Intel Core i7-4770K", prixUnitaire: 324.96, quantite: 0, montantHT: 324.96, montantTTC: 389.95 }, 
 
       { id: 3, reference: 789, titre: "ASUS MAXIMUS VII RANGER", prixUnitaire: 134.96, quantite: 0, montantHT: 134.96, montantTTC: 161.95 } 
 
     ]; 
 

 

 

 
     $scope.PrixTotalTTC = function() { 
 
      var resultTTC = 0; 
 

 
      angular.forEach($scope.articles, function (article) { 
 
       resultTTC += article.montantTTC * article.quantite; 
 
      }); 
 
      return resultTTC; 
 
     }; 
 

 
     $scope.PrixTotalHT = function() { 
 
      var resultHT = 0; 
 

 
      angular.forEach($scope.articles, function (article) { 
 
       resultHT += article.montantHT * article.quantite; 
 
      }); 
 
      return resultHT; 
 
     }; 
 

 
     $scope.NombreArticle = function() { 
 
      var resultArticle = 0; 
 

 
      angular.forEach($scope.articles, function(article){ 
 
       resultArticle += article.quantite; 
 
      }); 
 
      return resultArticle; 
 
     }; 
 

 
     $scope.AjouterArticle = function() { 
 
      $scope.articles.push({ 
 
       id: '', 
 
       reference: '', 
 
       titre: '', 
 
       prixUnitaire: 0, 
 
       quantite: 0, 
 
       montantHT: 0, 
 
       montantTTC: 0 
 
      }); 
 
     }; 
 

 
     $scope.SupprimerArticle = function(index) { 
 
      $scope.articles.splice(index, 1); 
 
     }; 
 

 
    }]);
<html lang="en-us"> 
 
<head> 
 
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous"> 
 
<link rel="stylesheet" href="style.css"> 
 
<script src="//code.angularjs.org/1.6.6/angular.min.js"> 
 
</script> 
 
<script src="app.js"></script> 
 

 
</head> 
 
<body ng-app="Commande" ng-controller="commandeController"> 
 
<h1>Bon de commande</h1> 
 
    <div class="content"> 
 
     <div class="col-md-12"> 
 
      <table class="table table-striped table-hover table-responsive"> 
 
       <thead> 
 
        <tr> 
 
         <th>#</th> 
 
         <th>Référence</th> 
 
         <th>Titre</th> 
 
         <th>Prix unitaire HT/€</th> 
 
         <th>Quantité</th> 
 
         <th>Montant HT/€</th> 
 
         <th>Montant TTC/€</th> 
 
         <th>Supprimer</th> 
 
        </tr> 
 
       </thead> 
 
       <tbody> 
 
        <tr ng-repeat="article in articles"> 
 
         <th> 
 
          <input type="number" ng-model="article.id" class="form-control bfh-number" placeholder="Id" min=0> 
 
         </th> 
 
         <td> 
 
          <input type="number" ng-model="article.reference" class="form-control bfh-number" placeholder="Référence" min=0> 
 
         </td> 
 
         <td> 
 
          <input type="text" ng-model="article.titre" class="form-control" placeholder="Titre"> 
 
         </td> 
 
         <td> 
 
          <input type="number" ng-model="article.prixUnitaire" class="form-control bfh-number"> 
 
         </td> 
 
         <td> 
 
          <input type="number" ng-model="article.quantite" class="form-control bfh-number" min=0> 
 
         </td> 
 
         <td> 
 
          <input type="number" ng-model="article.montantHT" class="form-control bfh-number" min=0> 
 
         </td> 
 
         <td> 
 
          <input type="number" ng-model="article.montantTTC" class="form-control bfh-number" min=0> 
 
         </td> 
 
         <td> 
 
          <a href ng:click="SupprimerArticle($index)"><i class="fa fa-times delete"></i></a> 
 
         </td> 
 
        </tr> 
 
        <tr class="success"> 
 
         <th class="success">TOTAL</th> 
 
         <td class="success"></td> 
 
         <td class="success"></td> 
 
         <td class="success"></td> 
 
         <td class="success">{{ NombreArticle() }} article(s)</td> 
 
         <td class="success" ng-style="PrixTotalHT() >= 1000 && {'font-weight': 'bold'}">{{ PrixTotalHT() | number:2 }} €</td> 
 
         <td class="success" ng-style="PrixTotalHT() >= 1000 && {'font-weight': 'bold'}">{{ PrixTotalTTC() | number:2 }} €</td> 
 
         <td class="success"></td> 
 
        </tr> 
 
       </tbody> 
 
      </table> 
 
      <a href ng:click="AjouterArticle()" class="btn btn-primary">Ajouter un article <i class="fa fa-plus"></i></a> 
 
     </div> 
 
    </div> 
 
</body> 
 
</html>

这是我的代码。

+0

寻求调试帮助的问题**(“为什么不是这个代码工作?”)**必须包含所需的行为,特定的问题或错误以及在问题本身中重现问题所需的最短代码。没有明确问题陈述的问题对其他读者无用:欢迎使用堆栈溢出。请阅读这个。 :https://stackoverflow.com/help/on-topic –

+0

当我运行代码片段但在编辑器中不工作时,它的工作就在这里。 –

+0

你应该更详细地解释你想要得到什么,以及代码得到的结果。 – Assafs

回答

0

听起来像是你需要一个内容管理系统CMS),如MAMP,XAMPP或类似的。您基本上需要运行本地服务器以使JavaScript代码正常工作(以及您可能使用的任何PHP)。简单的解决方案,如果只需要JavaScript,就是使用Node.js.

+0

嗨@AlekseySolovey,Angular是为前端单页应用程序。我想我已经进入了一些错误的头部,以获得cdn集成Ajs。 –

+0

你可以随时下载angularjs并作为脚本手动导入,但是如果你的代码在这里工作,我会想象你需要一个本地服务器 –