CSS Selectors do not apply to AngularJS ng-class

In the process of developing an Ionic application, I encountered a strange issue where the dynamic class set through ng-class suddenly stopped working. Despite being correctly resolved in the HTML, the selectors associated with it simply do not apply.

Here is the template snippet in question:

<ion-nav-bar class="bar-positive nav-title-slide-ios7" ng-class="{{ app.style }}">
        <ion-nav-back-button class="button-clear"><i class="icon ion-chevron-left"></i> Back</ion-nav-back-button>
</ion-nav-bar>

Upon inspection, the resulting HTML seems to be completely fine:

<ion-nav-bar class="bar-positive nav-title-slide-ios7 bar bar-header nav-bar disable-user-behavior  no-animation" ng-class="Tallin">
  <ion-nav-back-button class="button-clear button back-button ng-hide"><i class="icon ion-chevron-left"></i> Back</ion-nav-back-button>
  <div class="buttons left-buttons"> <span class="">
    <button menu-toggle="left" class="button button-icon icon ion-navicon"></button>
  </span></div>
  <h1 ng-bind-html="title" class="title ng-binding" style="left: 51px; right: 51px;">Home</h1>
  <div class="buttons right-buttons"> </div>
</ion-nav-bar>

However, attempts to use .Tallin in CSS selectors prove futile as they don't seem to have any effect. Interestingly, using it as a regular static class works perfectly fine, indicating a possible issue with how the dynamic class is being processed.

This anomaly only surfaced recently without a clear indication of what might have caused it. Any insights or suggestions would be greatly appreciated.

Answer №1

Get rid of the curly braces {} from the class attribute. Instead, use ng-class="app.style"

Answer №2

ng-class requires an expression, while {{ }} injects HTML content.

You can either directly reference a class in your HTML:

<p ng-class="class">Text</p>

or call a function from your controller:

<p ng-class="getClass()">Text</p>

or utilize the object syntax:

<p ng-class="{ 'red': true }">Text</p>

Essentially, any valid expression can be used with ng-class.

JSFIDDLE: http://jsfiddle.net/1Lbjj8yf/

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

Achieving a collapsing navbar on click in Bootstrap 5

Is there a way to collapse this navigation bar after clicking on a link, without using a JavaScript event listener or the data-bs-toggle and data-bs-target methods mentioned in this article? I tried both methods but they are not working with my code. Here ...

Maintain the dropdown selection while the table is being updated

My table updates every few seconds and each row has a dropdown menu that allows users to take actions on that row. However, the problem is that when new data is received from the database, the dropdown menu closes if it was open. This can be frustrating f ...

Is it possible to utilize both jQuery and AngularJS in our web application?

Is it feasible to incorporate both jQuery and AngularJS in our web application? Some sources suggest avoiding using them together due to their distinct lifecycles. We need to develop a responsive web application using ASP.NET WebApi and AngularJS. To achi ...

Navigating in Angular is easy when you understand how to use special characters such as

In order to set a unique path in AngularJS routing, I am looking for the following features: An optional parameter The ability to accept values of a relative path Here are some examples of the parameter values I need to work with: /ABC /ABC/123 /ABC/12 ...

Anchor tag remains in fixed location in HTML

Here's a link that I need help with: <a id="readmore" href="#">READ MORE</a> Currently, when the user clicks on this hyperlink, I am using Jquery to toggle the content below it to show/hide the content. However, I have encountered an ...

Is there a way to retrieve the left offset of a floating element even when it is positioned outside the viewport?

My current situation involves creating several panels that are stacked side by side within a main container. Each panel takes up 100% of the viewport width and height. I want to be able to horizontally scroll to each panel when clicking on their respective ...

Switching Out Bootstrap Dropdown with Dropup (Varying functionality on two almost identical implementations)

In the midst of my project on Github Pages, I encountered an interesting issue involving replacing a bootstrap .dropdown with .dropup when the div's overflow-y: scroll causes the dropdown menu to be cut off or overflow. The functionality can be viewed ...

Angular Bootstrap causes misalignment of table column headings based on different properties in object

I have an object with two properties: person and vehicle. Both properties consist of arrays of data. I have separate column headings for the person and vehicle properties and display the data in tabular form. However, the column headings for both propertie ...

Issues with Access-Control-Allow-Origin in .NET Core Deployment on IIS Set up on Windows Server 2016

I have checked various sources like Microsoft Documentation, SO Answers, and even installed IIS CORS module, but I am still struggling to get it right. The issue arises with my .NET Core API 3.1 hosted on IIS at AWS EC2 Windows Server 2016 datacenter, acc ...

Unable to successfully send multiple values from input fields using forms in PHP

I am currently facing an issue with my HTML form that contains a field consisting of multiple selection boxes as shown below: <div class="form-group"> <select multiple name="Fee[]"> ...

The ng-repeat directive fails to automatically refresh itself when a new item is added via a dialog box

As a beginner in AngularJs, I am currently working on CRUD Operations using $http and ASP.NET MVC. Here is what I have done so far: I utilize ng-repeat to display a list of "Terms". There is a button that triggers a dialog box for inserting new "Ter ...

Accessing parent directive's function from child directive using attributes

Let's set the scene: <export-team> <ul> <li> <button buy-ticket="{{data}}" buy-callback="onBuyTicket()">buy</button> </li> <li> <button buy-ticket="{{data}}" buy-callback="onBuyTicket()">bu ...

The dropdown menu is obscured by the toolbar

When using ionic4/angular, I want a dropdown menu to display upon clicking on the ion-avatar. However, the dropdown menu is hiding in the toolbar. I have tried setting z-index but it did not work. Any suggestions would be appreciated. You can find the sta ...

Align columns responsively with Bootstrap and center overlay image

Experiencing issues with aligning responsive divs using Bootstrap. Here is the code in question: <div class="container-fluid"> <div class="row"> <div class="col-xl-5"> <img src=&quo ...

Is it just me or does this radio button in IE11 look like a pair of googly eyes?

Recently, I noticed a strange issue on a website I'm working on with radio buttons. While everything looks fine in most browsers, in IE11 some of the radio buttons appear like googly eyes. Could this be a bug specific to IE11 or am I missing something ...

Different approach for binding in Vue.js

Seeking Alternatives I am curious to find out if Vue.js offers a different approach for outputting data beyond the conventional curly braces. Is there a syntax similar to Angular's ng-bind directive that I could utilize? Although Vue.js primarily ut ...

Concealing buttons and Enabling others using ajax

I am facing a situation where I need to modify the behavior of a modal window on my webpage. The modal currently has two buttons for confirmation and cancellation, as shown in the code snippet below. Inside this modal, there is a <div class = "resp"> ...

Arranging Divs into Two Columns in CSS - A Simple Guide

I'm trying to display a variable number of divs across two lines, like this: [1] [3] [5] [7] [2] [4] [6] ... I've explored using the column-count property in CSS, but it doesn't quite fit my needs since it requires a fixed number of ...

Effect of Active or Focus on the HTML <ul> element

Check out this example of a UL tag: <ul style="list-style-type:none; padding:5px ; border:solid 1px #666666;"> <li>I am waiting </li> <li>I am waiting </li> <li>I am waiting </li> <li>I am wa ...

Jasmine - What is the best way to simulate a finally block?

After creating a controller in my test, I encountered an issue with the updateActionList function... this.createScope = function(scope) { if (scope) { this.scope = scope; } else { this.scope = $rootScope.$new(); } this.contro ...