Question: How can CSS styles be applied and removed conditionally in AngularJS?
Answer: AngularJS provides several directives for managing CSS styles dynamically:
Q1: Conditional Styling for Item Deletion:
Use ng-class to toggle a pending-delete class when an item is marked for deletion.
<div ng-repeat="item in items" ng-class="{'pending-delete': item.checked}"> ... <input type="checkbox" ng-model="item.checked"> </div>
Q2: Customizable User Interface:
Use ng-style to dynamically apply CSS styles based on user input.
<div class="main-body" ng-style="{color: myColor}"> ... <input type="text" ng-model="myColor" placeholder="enter a color name"> </div>
The above is the detailed content of How Can I Conditionally Apply and Remove CSS Styles in AngularJS?. For more information, please follow other related articles on the PHP Chinese website!