リソースからボタンリストを取得しました。t1、t2、t3、t4、t5、t6、t7、t8、t9、t10のような10個のボタンで構成されています。 2回目は同じボタンの色を緑色に変更します。ng-click機能を使用してボタンの色を変更する方法は?
これは私の方法
$scope.ng-click=gettable(table){
//
}
リソースからボタンリストを取得しました。t1、t2、t3、t4、t5、t6、t7、t8、t9、t10のような10個のボタンで構成されています。 2回目は同じボタンの色を緑色に変更します。ng-click機能を使用してボタンの色を変更する方法は?
これは私の方法
$scope.ng-click=gettable(table){
//
}
これは簡単です。
<button type="button" class="btn {{table.btnClass}}" ng-click="getTable(table)">
{{table.tablename}}</button>
とNG-クリック機能として:ちょうどthis-
for(var i = 0; i < $scope.tables.length; i++)
{
$scope.tables[i].btnClass = "btn-success";
}
のようなテーブルの列であなたのすべてのアイテムを持つもう一つのプロパティをバインドその後、HTMLで、次のようにこのクラスを割り当てます:
$scope.getTable = function(table) {
table.btnClass = table.btnClass == "btn-info" ? "btn-success" : "btn-info"
}
または、マニュアルカラーを変更する場合は、次のようにCSSで1つのクラスを作成します。
.red-button {
background-color: "red";
}
その後(私はあなたが使用することをお勧め)controllerAsの構文を使用して機能
$scope.getTable = function(table) {
table.btnClass = table.btnClass == "red-button" ? "btn-success" : "red-button"
}
はここに私の提案ですされてどのようにこの
<div class="col-sm-2 col-lg-1 col-md-1" ng-repeat="table in tables" style="margin-left:1px">
<button type="button" class="btn btn-success" ng-click="getTable(table)">{{table.tablename}}</button>
</div>
を行うことを教えてください:自分の$scope.ng-click=gettable(table){ ...... }
では、次で動作することができます。
HTML:
<div ng-repeat="table in ctrl.tables">
<button type="button" ng-click="ctrl.getTable(table)" ng-style="{ 'background-color': table.color }">{{table.tablename}}</button>
</div>
JS:
this.getTable = function(table) {
table.color = "red";
};
ボタンのデフォルトの色を緑に設定する方法 – SrinivasAppQube
ボタンのスタイル属性を使用してください... " style = "{'background-color':table.color} – FloG
var colors=['red','green','yellow','black','blue'];
$scope.color=null;
$scope.ng-click=gettable(table){
var colorToApply=colors[Math.floor(Math.random()*colors.length)];
$scope.color=colorToApply
}
今、あなたはここに
.green{
color:green;
}
.blue{
color:blue;
}
.red{
color:red;
}
.yellow{
color:yellow;
}
CSSルールを定義することができます
次に、あなたのビューであなたがボタンBTN-情報にあなたが色を変更し、
<button ng-style="color">Change color</button>
のような範囲の色にバインドしたいボタンの上にあなたの迅速なresponse.firstタイムクリックをありがとうngのスタイルを設定することができますにされます活性化される。もう一度同じボタンをクリックしてください。btn - 成功は適用されません。 – SrinivasAppQube
もう一度更新を確認してください。 – Abhinav
ここで設定する方法デフォルトの色はボタンの緑です。forループが私のために働いていない – SrinivasAppQube