Having trouble making class changes with ng-class

I am attempting to change the direction of the arrow in my checkbox by utilizing two classes with the assistance of ng-class. Unfortunately, it is not producing the desired outcome.

Below is my code:

Note: The angularJS CDN has already been incorporated.

test.php

<div class="container">
  <div class="row">
    <div class="col-md-12" >
      <div class="check-element animate-show-hide" ng-show="checked" style="display:inline-block;width:100%;overflow-y:auto;" >
        <ul class="timeline timeline-horizontal"  >
          <li class="timeline-item" ng-repeat="s in steps">
            <div class="timeline-badge" ng-class="{'navion':s.status === 1, 'timeline-badge-green':s.status === 0}"></div>
            <div class="timeline-panel">
              <div class="timeline-heading">
                <h4 class="timeline-title">{{s.status === 1 ? "In progress" : (s.status === 0)? (s.date | date:"MMM d, y") : "Pending"}}</h4>
              </div>
              <div class="timeline-body">
                <p>{{s.description}}</p>
              </div>
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</div>
<br>

<div id="ck-button">
  <label>
    <input type="checkbox" value="1"  ng-model="checked" aria-label="Toggle ngShow"><i ng-class="{onlineClass}"></i>
  </label>
</div>

style.css

label i {
    border: solid black;
    border-width: 0 3px 3px 0;
    display: inline-block;
    padding: 8px;
  }

  .up {
    -webkit-transform: rotate(-135deg);
    margin-left: 27%;
    margin-top: 38%;
  }

  .down {
    -webkit-transform: rotate(45deg);
    margin-left: 27%;
    margin-top: 18%;
  }

  div label input {
    margin-right:100px;
  }

  body {
    font-family:sans-serif;
  }

  #ck-button {
    margin:4px;
    background-color:#EFEFEF;
    border-radius:4px;
    border:1px solid #D0D0D0;
    overflow:auto;
    float:left;
  }

  #ck-button {
    margin:4px;
    background-color:#EFEFEF;
    border-radius:4px;
    border:1px solid #D0D0D0;
    overflow:auto;
    float:left;
  }

  #ck-button:hover {
    margin:4px;
    background-color:#EFEFEF;
    border-radius:4px;
    border:1px solid red;
    overflow:auto;
    float:left;
    color:red;
  }

  #ck-button label {
    float:left;
    width:4.0em;
    height: 40px;
    width: 40px;
  }

  #ck-button label span {
    text-align:center;
    padding:3px 0px;
    display:block;
  }

  #ck-button label input {
    position:absolute;
    top:-20px;
  }

  #ck-button input:checked + span {
    background-color:#911;
    color:#fff;
  }

j_TestCtrl.js

$scope.onlineClass = function(a) {
    return (a > 0) ? 'up' : 'down';
};

Answer №1

Considering that the onlineClass function is available, you can implement it like so:

<div id="checkbox-wrapper">
    <label>
        <input type="checkbox" value="1" ng-model="checked" aria-label="Toggle ngShow">
        <i ng-class="onlineClass(checked)"></i>
    >/label>
</div>

Answer №2

To properly execute the function in your ng-class code, make sure to add `()` after the function name and include a parameter since your function is defined as `function(a)`.

Here is an example:

<div id="ck-button">
    <label>
        <input type="checkbox" value="1"  ng-model="checked" aria-label="Toggle ngShow">
        <i ng-class="{onlineClass(checked)}"></i>
    >/label>
</div>

On another note, why alter a familiar web standard element that everyone understands?

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

The Ajax request is displaying the URL instead of the expected posted data

Here is the html code along with JavaScript that I am working on: <div id="input_form"> <fieldset> <form id="myform" method="post" action=""> seq: <input type="text" name="seq" id = "seq"><br><br> ...

How do I insert a variable into my email content using PHP?

Hey there, I have a form that captures Name, Email, Subject, Telephone Number, Message, and a checkbox. Unfortunately, I'm not very proficient in PHP. I've just started learning the basics and could use some guidance from you :) The Form < ...

How can I expand the notification pop-up in R Shiny?

I'm trying to figure out how to expand the notifications in R Shiny because right now they are cutting off longer error messages. Any suggestions? library(shiny) ui <- fluidPage( actionButton("test", "Test") ) server <- f ...

Trouble with fetching data for Line Chart via jQuery AJAX and ASP.NET MVC

I am working on incorporating a simple line chart from Google Charts into my project, but I am facing an issue with the data not loading correctly. I only require two values to be displayed: the hours worked and the days of the particular month. While I ca ...

Is the Owl carousel Auto Play feature malfunctioning when hovered over?

I seem to be encountering an issue with the auto play functionality of the owl carousel. I have uploaded and included all the necessary files, and it is functioning properly when initially loaded. The auto play feature works perfectly, but when I hover ove ...

"Utilize jQuery to load a file when hovering over a specific

How can I dynamically load an external file using jQuery when a user hovers over a specific div? I attempted to load the file like a CSS file on hover but was unsuccessful. Is it possible to load a CSS file on hover as I've seen in some examples? $(d ...

Is it possible to utilize both $uibModal and $uibModalInstance within the same controller to create a modal popup in an Angular project incorporating TypeScript?

Being new to Angular with Typescript, I encountered an issue while trying to implement a modal popup in Angular. The problem arises when I have a dropdown menu that triggers the opening of a modal popup with two buttons, "Yes" and "No". To handle this, I h ...

Personalizing text in HTML using JavaScript results

I have a modal dialog box function that pops up when a user clicks a button, triggered by a javascript/jquery script. The text displayed in the dialog is set up within an HTML div element that references the script function. My query is how to personalize ...

Loading tabs dynamically in Angular 2 based on header click event

I successfully created a custom tab component using Angular 2, and it is functioning well with the following usage: <us-tab-verticle> <vtab-content [tabTitle]="'Basic Information'"><basic-info> </basic-info></vtab- ...

Create Stylish Popups and Spacious Containers with CSS

A unique pure css popup was crafted by merging and . Hovering over "John Smith" triggers the appearance of the popup. The code for this can be seen at http://codepen.io/kikibres/pen/MwEgQX. However, there are some challenges being faced. The aim is to ke ...

React-Native has reached the maximum update depth, please check the new state

When I try to add and change the number (setNum(number+1)), I encounter an error message stating: Maximum update depth exceeded. This issue may arise when a component repetitively calls setState inside componentWillUpdate or componentDidUpdate. React enfor ...

Tips on accessing files saved in a one-to-many connection using Mongoose

I have multiple Schemas set up for Shops and Products. Each shop can have a variety of products, and I currently have 5 different shops with their own unique product listings. While I am able to save the products and find their corresponding IDs within eac ...

The execution of the 'yarn start-https' command encountered an error and exited with code 1

Struggling to set up the environment for a downloaded project. After running yarn install, yarn build, and yarn start-https, I encountered this error message: Error: error:0909006C:PEM routines:get_name:no start line at node:internal/tls/secure-context ...

Transforming the appearance of web elements using jQuery (graphic)

While there are numerous resources on changing CSS with jQuery, I seem to be having trouble getting my image to hide initially and show up when a menu tab is clicked. Any help would be greatly appreciated! ;) h1 { text-align: center; } .Menu { widt ...

Streamline repetitive scope attributes in AngularJS

After noticing that I was using a repetitive structure, I want to simplify it: <container> <clock property="data"></clock> <calendar property="data"></calendar> <alert property="data"></alert> </container ...

Is it possible to utilize Angular validation directives programmatically within a personalized directive?

In my exploration of HTML inputs, I have noticed a recurring pattern specifically for phone numbers: <input type="text" ng-model="CellPhoneNumber" required ng-pattern="/^[0-9]+$/" ng-minlength="10" /> I am interested in developing a unique directiv ...

Please refrain from altering the color of my flag on hover

I am working with a table that has rows marked with flags. Below is the CSS I have used: <table class="hovered no-border" data-url="@Url.Action("General", "Transport")"> <tbody> <tr> <td><input type="che ...

Alignment issues with the layout

I am facing an issue with two containers stacked on top of each other. The bottom container is wider than the top one, and both have auto margins set for the left and right sides. I want the top container to be aligned evenly on top of the bottom one. I c ...

Grid with a column range of 1 to 3 should be used

My website currently features a grid that can have anywhere from 1 to 3 columns. To ensure flexibility in the number of columns, I am using auto-fit: .grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min-content, 1fr)); gap: 40px; ...

Variables for Angular Material themes

My app has multiple theme files, and I select the theme during runtime. .client1-theme{ // @include angular-material-theme($client1-theme); @include all-component-colors($client1-theme); @include theme-color-grabber($client1-theme, $client1-a ...