html页面 在这里,我在每个列表中有两个按钮。当点击其中一个按钮时,将该列表项目显示在其他页面中。当点击下一个点击项目时,它也会将该项目带到同一页面。请给我建议或代码。
<ion-view ng-controller="searchctrl as nm">
<ion-content class="has-header">
<h2>Courses</h2>
<label class="item item-input">
<i class="icon ion-search placeholder-icon">
</i>
<input type="search" placeholder="search" ng-model="searchQuery"/>
</label>
<ion-list>
<ion-item class="item-icon-right" ng-repeat="news in newss | filter:searchQuery"
ng-click= "nm.selectNews(news.name)">
{{news.name}}
<div class="buttons">
<button class="button button-small button-positive" >
View
</button>
<button class="button button-small button-positive">
Add to Mycourse
</button>
</div>
</ion-item>
</ion-list>
js page
(function(){
var aapp = angular.module('starter');
aapp.controller('searchctrl', function($state, $scope){
$scope.newss = [
{name: 'HTML'},
{name: 'JavaScript'},
{name: 'Angular'},
{name: 'Ionic'},
{name: 'Asp.net'}
]
var nm=this;
nm.selectNews = function(newsname){
console.log(newsname);
$state.go(newsname);
}
});
}());
答案 0 :(得分:0)
首先使用数组来存储选择的项目:
rebase
然后,添加此功能,它将首先检查此项是否已添加,然后数量将被提升,否则项目将被推入购物车数组。
$scope.cart = [];
希望这会对你有所帮助......有什么疑问?