我有一张我正在使用的元素表。点击按钮“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我的功能。感谢您带领我走向正确的道路! –