list
ではなく、div
にアイテムを作ろうとしています。アイテムがクリックされた場合、div
は色が変わり、アイテムがカラムに追加されますが、アイテムを再びクリックするとアイテムは元の色と列の項目はなくなります。私はちょうど角をなしてそれをする方法を考えることができません。私は列に追加することができ、アイテムを削除する別のオプションに来た、削除ボタンがありますが、私はまだ選択と選択解除を行うことができます好奇心です。 angularJsのdiv /ボタンの選択と選択解除方法を教えてください。
この
は私が私の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-->
私のコントローラ(私はそれを最初に試みを与えるためにボタンを使用していた私のbtn btn-primary
クラスを無視する)持っているものですどのようにこれを行うことができるかというアイデアを持っているのですが、私はコードを書くことはできません。
P.S.コードは単純です、私はコードスクールでそれを学び、自分自身を教育するための楽しみのために何かを作りたがっていました。事前の人々
あなたのニーズを理解することができません。「私はリストにないのにdivで作成しようとしています。リストまたはdivはどこですか? –
クリックでクラスを変更するためにng-classを使用する –
あなたは私たちにjsfiddleを教えてください。それは非常に良いでしょう。 – WhoAmI