我有一張我正在使用的元素表。點擊按鈕「Adauga la meniu」時,我希望該元素的詳細信息存儲在名爲currentMenu的對象數組中,並顯示在addtomenu.html視圖中。推在AngularJS路由中不起作用
addtomenu.html
<h3>My menu</h3>
<table>
<tr>
<th>Aliment</th>
<th>Calorii</th>
<th>Proteine</th>
<th>Lipide</th>
<th>Carbohidrati</th>
<th>Fibre</th>
</tr>
<tr ng-repeat="app in currentMenu">
<td>{{ app.name }}</td>
<td>{{ app.calorii }}</td>
<td>{{ app.proteine }}</td>
<td>{{ app.lipide }}</td>
<td>{{ app.carbohidrati }}</td>
<td>{{ app.fibre }}</td>
</tr>
</table>
<a href="#/tabel">Back to table</a>
一些app.js
app.config(function($routeProvider){
$routeProvider
.when("/tabel",{
templateUrl: "tabel.html",
controller: "HomeController"
})
.when("/addtomenu",{
templateUrl: "addtomenu.html",
controller: "HomeController"
})
});
的一些HomeController的
$scope.currentMenu = [
{
name: '',
calorii: '',
proteine: '',
lipide: '',
carbohidrati:'' ,
fibre: ''
}
];
我添加到菜單功能
$scope.addItem = function (product){
alert("OK");
$scope.currentMenu.push({name: product.name, calorii: product.calorii, proteine: product.proteine, lipide: product.lipide, carbohidrati: product.carbohidrati, fibre: product.fibre});
window.location = '#/addtomenu';
};
功能的addItem將在這裏稱爲:
tr ng-repeat="product in produse.products | orderBy:predicate:reverse | filter:query">
<td class="left">{{ product.name }}</td>
<td>{{ product.calorii }}</td>
<td>{{ product.proteine }}</td>
<td>{{ product.lipide }}</td>
<td>{{ product.carbohidrati }}</td>
<td>{{ product.fibre }}</td>
<td><button ng-click="$parent.removeItem(product)" class="buttonimage"><img src="images/remove.png"/></button></td>
<td><button ng-click="$parent.addItem(product)" class="buttonimage"><img src="images/addtomenu.png"/></button></td>
</tr>
完全plunker這裏:https://plnkr.co/edit/HyXt7hWGtle1gWrv1U42?p=preview
我希望你讓我明白了什麼是錯的,感謝您的幫助!
現在對我來說很有意義。我會嘗試實現並optymyze我的功能。感謝您帶領我走向正確的道路! –