list
içinde değil, div
ürününde ürün oluşturmaya çalışıyorum ve bir öğeye tıklandığında div
farklı renklerde olacak ve öğe bir sütuna eklenecek, ancak öğe tekrar tıklandığında öğe değiştirilecek Orijinal renk ve sütunda öğe gitmiş olacak. Sadece açısal şekilde nasıl yapılacağını düşünemiyorum. Sütunu ekleyebilmek ve öğeyi kaldırabilmek için başka bir seçeneğe geldim, bir çıkarma düğmesi var ancak seçim ve seçimin nasıl yapılacağını merak ediyorum. AngularJs'de bir div/düğme nasıl seçilir ve kaldırılır?
Bu
benim html js//Controller for app features
app.controller("FeaturesController", function(){
this.apps = features;
this.listAppPrices = [];
// add name and price into the new array which is used to show in the table
this.addPrices = function(name, price){
//Checks if the exact name, price property exists in the array and return boolean
var found = this.listAppPrices.some(function (e){
console.log(e.name);
return ((e.name === name) && (e.price === price)) ;
});
//If found not true then push the new values into the array
if(!found){
this.listAppPrices.push({name: name, price: price});
}
};
// adds all the prices of the array which gives the total
this.totalAppPrice = function(){
var total = 0;
for(var i = 0; i < this.listAppPrices.length; i++){
total += this.listAppPrices[i].price;
}
return total;
};
// remove the whole object in the array when remove is clicked
this.remove = function(index) {
this.listAppPrices.splice(index, 1);
};
});
I
<!--Select App Features-->
<div class="panel-heading" ng-controller="FeaturesController as featuresCtrl">
<h1 class="text-center">App Features</h1>
<div class="text-center">
<div ng-repeat="app in featuresCtrl.apps" class="btn btn-primary platform-btn-style" ng-click="featuresCtrl.addPrices(app.name, app.price)">{{ app.name }}</div><br>
</div>
<div>
<table class="table table-striped table-hover">
<thead>
<tr>
<th>Device Added</th>
<th>Device Price</th>
<th></th>
</tr>
</thead>
<tr ng-repeat="appList in featuresCtrl.listAppPrices">
<td>{{ appList.name }}</td>
<td>{{ appList.price }}</td>
<td><button class="btn btn-default" ng-click="featuresCtrl.remove($index)">Remove</button></td>
</tr>
</table>
<div>Total : {{ featuresCtrl.totalAppPrice() }}</div>
</div>
</div><!-- end select app features/FeaturesController-->
Benim denetleyicisi (ben o ilk etapta denemeye düğmesini kullanarak benim btn btn-primary
sınıfları görmezden) ne var Bunun nasıl yapılabileceğine dair bir fikre sahip olmakla kalmayıp, onu yazacak kodları düşünemiyorum.
P.S. Kodlar basit, ben sadece kod okulda öğrendim ve kendimi eğitmek için eğlenceli bir şey yaratmak istedim. peşin insanlar
İhtiyaçlarınızı anlayamıyorum, "Listede değil, ancak liste içinde yer almayı deniyorum" anlamına ne geliyor? Liste veya div nerede? –
BTW sınıfındaki –
tıklama sınıflarını değiştirmek için lütfen bir jsfiddle verebilir misiniz? Bu çok daha iyi olurdu. – WhoAmI