這是我的代碼爲角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>
這是我的代碼。
尋求調試幫助的問題**(「爲什麼不是這個代碼工作?」)**必須包含所需的行爲,特定的問題或錯誤以及在問題本身中重現問題所需的最短代碼。沒有明確問題陳述的問題對其他讀者無用:歡迎使用堆棧溢出。請閱讀這個。 :https://stackoverflow.com/help/on-topic –
當我運行代碼片段但在編輯器中不工作時,它的工作就在這裏。 –
你應該更詳細地解釋你想要得到什麼,以及代碼得到的結果。 – Assafs