Mastering the art of applying and eliminating classes in AngularJS

Is it possible to adjust the size of the table by clicking a button on the side navigation bar? When the button is clicked, the table width should expand to maximum.

<table init-table="rowCollection" class="table table-striped table-responsive table-hover table-bordered" style="width:auto "overflow-x:auto">
  <thead>
    <tr class="width">
      <th>Id</th>
      <th class="col-md-4">Abstract</th>
      <th class="col-md-2">RTC Workspace</th>
      <th class="col-md-2">Requester</th>
      <th>Build Start</th>
      <th>Build Status</th>
      <th>Actions</th>
    </tr>
  </thead>
  <tbody>
    <tr ng-repeat="row in rowcollection">
      <td>{{row.build_id}}</td>
      <td>{{row.abstract}}</td>
      <td>{{row.rtc_workspace}}</td>
      <td></td>
      <td>{{row.build_start}}</td>
      <td>{{row.build_status}}</td>
      <td>
        <button type="button" class="btn btn-primary"  ng-click="approve(row)">Approve</button>
      </td>
    </tr>
  </tbody>
</table>

<!--panel-->
<div class="col-lg-12">
  <button type="button" class="btn btn-default btn-primary" ng-click="ShowHide()"> <span class="glyphicon glyphicon-eye-open"></span>&nbsp Sidebar toggle</a></button
</div>

Are there any methods to add a class that, when clicked on the button, can remove the class or perform similar actions?

Answer №1

Here is a brief outline of how to achieve the desired functionality:

Create two CSS classes, named .full-width and .custom-width, then set a boolean variable within a function triggered by an event (such as ng-click). Apply these classes using ng-class based on the status of this variable.

ng-click = "clickMethod()";

In the corresponding controller:

$scope.fullwidth = false;
$scope.clickMethod = function () {
     $scope.fulltable = true;
}

In your HTML:

Utilize ng-class on the element, while also removing the width property from the table's inline style.

ng-class="fulltable? 'full-width' : 'custom-width'"

Answer №2

It seems like you are interested in using the ng-class directive.

.strike {
    text-decoration: line-through;
}
.bold {
    font-weight: bold;
}
.red {
    color: red;
}
.has-error {
    color: red;
    background-color: yellow;
}
.orange {
    color: orange;
}
<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Example - example-ng-class-production</title>
  <link href="style.css" rel="stylesheet" type="text/css">
  

  <script src="//code.angularjs.org/snapshot/angular.min.js"></script>
  

  
</head>
<body ng-app="">
  <p ng-class="{strike: deleted, bold: important, 'has-error': error}">ng-class Syntax Example</p>
<label>
   <input type="checkbox" ng-model="deleted">
   deleted (apply "strike" class)
</label><br>
<label>
   <input type="checkbox" ng-model="important">
   important (apply "bold" class)
</label><br>
<label>
   <input type="checkbox" ng-model="error">
   error (apply "has-error" class)
</label>
</body>
</html>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Updating a validation directive on $watch in AngularJS version 1.2

I created a directive for validation on a multi-select that allows for dynamic length validation of selected items. The directive is used like this: (function() { 'use strict'; angular .module('myModule') .dire ...

Alert Div from Bootstrap fails to appear during the second ajax request if the first ajax request is canceled

I've implemented a dismissible alert in my HTML file that starts off hidden. Here's the code snippet: <div class="alert alert-dismissible" role="alert" id="msgdiv" style="margin-bottom:5px;display: none;"> <button type="button" clas ...

Having trouble accessing the $scope property value in AngularJS

1. script.js var appProfileInfo = angular.module('profileInfoApp', ['ngMaterial','ngAria','ngAnimate','ngRoute' ]); 2. messageController.js appProfileInfo.controller('messageController', functi ...

Trouble with data binding in AngularJS when using the input element

I am encountering an issue with my AngularJS code. When I try to input text into the textbox, it is not appearing in the binding. <!DOCTYPE html> <html lang="en"> <head> <script src="js/angular.js"></script> <scr ...

What could be the reason my div is not displaying correctly?

I am currently developing a game using HTML, CSS, and jQuery. The game will involve falling blocks that the player needs to avoid. However, I am facing an issue with my jQuery implementation. When selecting a theme (only the dark theme is currently functi ...

"Create a sleek slider with a modern Apple store aesthetic using Javascript

While I am willing to put in some effort, I am a bit lost at the moment. I am attempting to create a slider similar to the one featured on the home section of the Apple website. How can I enable a click on an image to navigate through slides? Alternatively ...

Code error: JSON unexpected token "&" encountered

When utilizing the $http.get() method for a GET request, the response is in JSON format, but some characters are HTML encoded. For example, the double quote " is encoded as &quot;. { &quot;description&quot;:&quot;invalid&quot;, ...

Using Clip Path will result in the content always being hidden if it

Here is an example I created: div { -webkit-clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%); clip-path: polygon(0 0, 100% 0, 85% 100%, 0% 100%); background-color: red; width: 150px; height: 150px; position: relative; } ul{ position: absolute; ...

Transferring data between various stages of the user interface

As a newcomer to angularJs, I find myself facing an issue with two forms existing in different UI states (URLs) labeled as Step 1 and Step 2. The process requires filling up Step 1 and moving to the next step by clicking the NEXT button, which then leads t ...

Halt hovering effect after a set duration using CSS or Vanilla JavaScript

Looking for a way to create a hover effect that lasts for a specific duration before stopping. I want the background to appear for just 1 second, even if the mouse remains hovering. Preferably using CSS or JavaScript only, without jQuery. To see my curren ...

How to align multiple span elements vertically using HTML and CSS

<div class="row history"> <div class="col col-50 histroy1"> <span class="my-orders">Statistics</span> <span class="my-orders-numbers">27</span> </div> <div class="col col-50 histroy ...

Center Align Element Vertically with pull-right Class in Bootstrap

HTML Code: <h5> <span style="vertical-align:central"><i class="fa fa-angle-right pull-right" style="font-size: x-large;"></i></span> <img src="/myimage.jpg" /><span style="padding-left: 1em"></span> <b> ...

The width of the column is not the same

Despite setting both columns to equal widths using col-sm-6 in Bootstrap, the column widths are not actually equal. One appears smaller while the other is larger. If you have a solution to this issue that works on both mobile and laptop devices, please s ...

Displaying a momentjs object within Angular templates

Looking to display a momentjs object, not an ISO8601 string, in AngularJS templates. For example: $scope.time = moment(); When I try the following in my template: <span ng-bind="time"></span> or <span>{{time}}</span> I want to ...

Troubleshooting a Next.js background image problem when hosting on Netlify

I've encountered an issue while attempting to deploy a nextjs website on Netlify. Everything works perfectly on my local server, but once it's on Netlify, the background image URL changes and the image becomes invisible. Original CSS code: backg ...

Encountering issues loading background image with Reactjs and Webpack

I've encountered an issue while trying to load a background image in my React project from a custom CSS file. I am currently using Webpack 4. .bgimage { height: 100vh; background: url('../images/header.jpg'); } Unfortunately, the image ...

UI-Router fails to execute controller code in the presence of a view section

I'm facing a rather unusual issue where it seems that a simple views template is preventing a controller from being executed, and I can't quite figure out why. I've put together a simple plunker to demonstrate. Here is the code: angular.mod ...

Can you identify the method used to apply CSS classes to an element?

Looking for clarification, I've noticed a pattern of "adding" (although unsure if that's the correct term) classes to elements in HTML UI frameworks. For instance, considering an element with these class attributes: class="mif-earth mif-2x" To ...

Tips on how to align a wrapper-div in the center without affecting the positioning of the

I am looking to keep my page perfectly centered in the browser without affecting the content (similar to how align-text: center works). Specifically, I want to center my wrapper-div. How can I achieve this? Here is a simplified version of my current page ...

The functionality of ItemSliding appears to be disabled when used in combination with

Could you please help me figure out why the Me button is not visible? I implemented the ItemSliding component. Here is the link to the stackblitz project. The issue is within the home folder. I am trying to create a list like the one below: UI https:// ...