我正在开发一个AngularJS Ionic Meteor应用程序,我需要根据它的内容(浮动)改变离子卡的botton框的背景色。范围如下:
data<=80
81 < data <= 160
161 < data <= 233
234 < data<= 317
318 < data <= 400.是否有一种CSS方法来做这件事,或者用一种AngularJS方式代替?
发布于 2015-11-10 20:43:29
你可以用ngClass。只需设置CSS背景色属性,并在控制器中设置适当的类,例如:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
$scope.submit = function() {
if ($scope.data <= 80) $scope.rangeColor = "red";
// Add more conditional statements
else $scope.rangeColor = "blue";
}
}.card {
border-style: solid;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="MyCtrl">
<h4>Data:</h4>
<form ng-submit="submit()">
<input type="text" name="data" ng-model="data" required>
<input type="submit" id="submit" value="Submit" />
</form>
<br />
<div ng-class="rangeColor" class="card">
<div class="item item-text-wrap">
This is a basic Card which contains an item that has wrapping text.
</div>
</div>
</div>
</body>
还可以在HTML元素中实现条件语句:
var myApp = angular.module('myApp', []);
function MyCtrl($scope) {
}.card {
border-style: solid;
}
.red {
background-color: red;
}
.blue {
background-color: blue;
}<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body ng-app="myApp">
<div ng-controller="MyCtrl">
<h4>Data:</h4>
<input type="text" name="data" ng-model="data" required>
<br />
<br />
<div ng-class="{'red': data <= 80, 'blue': data > 80}" class="card">
<div class="item item-text-wrap">
This is a basic Card which contains an item that has wrapping text.
</div>
</div>
</div>
</body>
发布于 2015-11-10 20:42:28
https://stackoverflow.com/questions/33639124
复制相似问题