Should ng-binding be avoided in CSS selectors as a general rule?

Recently, I stumbled upon this code snippet in our codebase:

li.ng-binding span {
    font-size: 13px;
    font-family: Arial, Helvetica, sans-serif;
    font-weight: bold;
}

The selector above doesn't actually apply to one of the intended 'li' elements due to the presence of .ng-binding within it. Even though this code functions as expected, should including ng-binding in a CSS selector be considered a best practice?

Answer №1

Your reservations are valid. The primary purpose of CSS is to separate the content of a document from its presentation (structural separation). Angular serves as an intermediary for binding attributes to HTML DOM elements, making it necessary to use standard or custom directives like ngStyle to style DOM elements effectively.

Additionally, upon further investigation, there is a "ng-binding" class used internally by Angular. By inspecting the source code for ngBind, we can see that it adds this class and links the binding with .data:

In Angular versions before 1.3, there is a reference to this:

 element.addClass('ng-binding').data('$binding', attr.ngBindHtml);

I do not recommend utilizing this class.

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

insert a gap between two elements in the identical line

Is there a way to create spacing between two text fields in the same row? I have tried using margins, paddings, and display flex in the css file but haven't been successful. import "./styles.css"; import TextField from "@material-ui/cor ...

Variable scope not properly maintained when there is a change in the Firebase promise

I am currently working on developing a controller function to handle signup submissions using Firebase. However, I've encountered an issue where the variables within the scope (controllerAs: $reg) do not seem to update correctly when modified inside a ...

What is the best way to ensure a grid remains at 100% width when resizing a browser window?

Within the div element, I have two child divs. One has the class col-md-2 and the other has the class col-md-10.Check out a sample view here In the image provided, the div containing hyperlinks (Database edit, invoice, preview) is not taking up 100% width ...

Removing scrollbar from table in React using Material UI

I successfully created a basic table using react and material UI by following the instructions found at: https://material-ui.com/components/tables/#table. The table is functioning properly, but I am finding the scrollbar to be a bit inconvenient. https:// ...

Using AngularJS and Jasmine to tackle challenges in writing spec tests

After setting up my seed and successfully getting Jasmin Running (huge thanks to SoEzPz for the assistance), I encountered an issue with my specs. When I tried to write a spec on a controller, it resulted in errors. However, when running an isolated spec, ...

Angular event triggered when updating input values from the model

I have developed a custom directive to add functionality to input fields with a specific class. I want to trigger events on blur and focus to update the label style based on Material Design principles. However, when using ng-model in Angular, I also need t ...

Basic $http.get request including parameters

I've been attempting to send an HTTP request using the AngularJS $http service like this: $http.get('http://myserver:8080/login?', { params: {username: "John", password: "Doe" }, headers: {'Authorization': ...

Designing motion graphics for a browser game

As I delve into learning about Node.js, Angular.js, Socket.io, and Express.js, my current project involves creating a multiplayer poker game like Texas Hold 'Em. However, despite spending a considerable amount of time browsing the internet, I have bee ...

Ways to select the element based on a specific CSS property value in the inline style

As a novice in the world of Javascript, I am currently attempting to select an element within an array of images where the opacity is set to 1. Could someone please guide me on how to achieve this? I've tried using hasAttribute, but I'm unsure ho ...

What methods can be used to keep divs from breaking onto separate lines?

My approach involves using divs to mimic a table structure. Below is the header section of this table: <div id="table-header"> <div id="header-row"> <div class="rate-rule-column s-boarder"> ...

Exploring the Power of JQuery with Hover Effects and SlideToggle

I was struggling to keep the navbar displaying without it continuously toggling when my pointer hovered over it. I just wanted it to stay visible until I moved my pointer away. <script> $(document).ready(function(){ $(".menu-trigger").hover(funct ...

Kendo Grid with locked height

Using a grid with some elements locked, we have established a CSS-defined minimum and maximum height for the grid. .k-grid-content { max-height: 400px; min-height: 0px; } An issue arises when setting the height of the locked grid. If the grid&a ...

After creating a new Packery using AngularJS, the getElementById function may return null

Alright, so I've got this HTML markup: <button ng-click="create()">create list</button> Every time I click it, I create a new list using the Packery jQuery plugin. app.directive('packery', ['$compile', function($com ...

What are the reasons behind the asynchronous behavior of Angular translate in version +2?

I have been using angular translate version 1.x for a while now and I find the $translate service quite easy to use. When working with this version, you can simply do the following in a controller: $scope.whatever = $translate('WHATEVER'); How ...

The process of obtaining and sending a token from an HTML page while submitting a form request to a Laravel 5 application involves a few key steps

My application consists of the client side being written in HTML and Angularjs, while the server-side is using Laravel 5. Every time I submit my form, I send the models using $http to a route in my Laravel 5 app, but I continuously encounter the error: pr ...

Nested SetTimeout function fails to execute

Attempting to implement a button that provides feedback for its actions, I am faced with a challenge in Angular. After sending a put request to the server, the button's state changes to show this action. Upon receiving a response, the button's st ...

The header that sticks on scroll is annoyingly blocking the content

I managed to create a sticky on-scroll header/navigation bar successfully. Here is how it looks now However, I encountered an issue. When it reaches the top, it automatically 'covers' the top part of my content, which has text on it, and I don& ...

What is the best way to create a Protractor expected condition that verifies the presence of a specific CSS class?

After clicking on the button with the id 'public1', the class goes from ng-pristine to ng-dirty. Here's an example: <input id="public1" class="tile-checkbox ng-valid ng-dirty"> Some Text</input> I am looking for a way to write ...

What is the reason behind modern browsers continuing to add spaces between inline blocks when there is whitespace present?

Consider the following HTML markup: <div class="inlineblock">one</div> <div class="inlineblock">two</div> <div class="inlineblock">three</div> Accompanied by this CSS style: .inlineblock{ display: inline-block; } ...

Ways to access a component from Controller?

How can I access the current DOM/jQuery element from within a Controller while running 'legacy code'? function EmailformController($scope) { // Need to find a way to grab the current element here } ...