Enhance the design of a label with AngularJS upon detecting a change in a text input field

I have been researching how to accomplish this task, but so far I have had no success. As someone who is not very experienced with web development, I wonder if the solution is so basic that no one even bothers to ask about it :(

Let's say we have an HTML text input field paired with a label, like so:

<label for = "stuff">Stuff</label>
<input type = "text" name = "stuffz" id="stuff" value = "hello!">

Now imagine that the value of the text input field changes. Is there a way to use AngularJS to change the style of the label (for instance, turning it green) when this event occurs? I have explored using ng-change and ng-class, but I lack the knowledge on how to effectively implement them in this context.

Any assistance would be greatly appreciated!

Answer №1

To implement this feature, you can utilize a combination of ngClass and ngChange:

angular.module('example', []);
.awesome {
  color: blue;
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>

<div ng-app="example">

<label for="items"
       ng-class="{ 'awesome' : !!changed }">
  Items
</label>
<input type="text"
       id="items"
       ng-model="myData"
       ng-change="changed = true">
  
</div>

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

How can I modify the color of JavaFX text using CSS?

Looking to jazz up my JavaFX application with some custom CSS styling. Managed to link a stylesheet to my app using the following code: //Java code FXMLLoader loader = new FXMLLoader(MainApp.class.getResource("/path/to/fxml")); Scene sce ...

What method is being used by this website to carry out this specific task?

I recently came across this website, , and I was intrigued by the functionality of the matrix entry feature. By clicking on the bracket icon next to the H2O icon, you can access it. Upon accessing the matrix entry function, users are prompted to input th ...

Guide to importing a scss file into a scss class

Is there a way to apply a different theme by adding the "dark-theme" class to the body? I've attempted the following implementation: @import '../../../../node_modules/angular-grids/styles/material.scss'; .app-dark { @import '../../. ...

Identify and emphasize unfilled inputs in a form using Bootstrap

I am working on an "Update Profile" form and I want to draw attention to empty input fields that are not required but would be beneficial for users to fill in. Is there a way to highlight these empty fields, perhaps with a glowing effect or some other form ...

Obtaining data with jQuery.Ajax technology

I am attempting to retrieve real-time data from a different URL and display it in a text field every second without refreshing the entire page. The content of the URL is constantly changing, so I want the field to update accordingly. However, despite my ef ...

Creating a user-friendly mobile navigation bar

Can someone help me with the code to create a button that displays the navigation bar when needed and hides it when not in use, similar to the one on apple.com? I'm working on this for a mobile device and would appreciate any suggestions or correction ...

We have come across a project on CodePen that utilizes Three.js, and we are looking to customize its color scheme

We stumbled upon a fascinating blob experiment on Codepen (https://codepen.io/vcomics/pen/ZwNgvX) and were eager to incorporate it into our project. However, we encountered an issue with the color changing feature on this perlin object (rcolor, gcolor, bco ...

CSS positioning causing a performance bottleneck

Does utilizing a large amount of absolute and fixed positioning in my HTML app lead to performance degradation? Looking for insights from experienced HTML professionals. ...

Using media queries in CSS to create responsive designs

<link type="text/css" rel="stylesheet" media="only screen and (max-device-width: 480px)" href="/assets/css/phone.css" /> <link type="text/css" rel="stylesheet" media="only screen and (min-device-width: 768px)" href="/assets/css/tablet.css" /&g ...

How can I change the text of a single button by clicking on it without affecting the other buttons that share the same

Currently, I am implementing a posting system where posts can be added using a button. The posts have two additional buttons - one to show/hide content and the other to delete content. I am utilizing jQuery's slideToggle event to toggle the visibility ...

jQuery loads browser cache to override transitions in the body class

My .load ajax function: 1) Click link 2) The requested page loads with a smooth css transition animation (applying/removing body classes) 3) If the page loads faster than 400ms, it should wait before revealing the page by removing the body class While ...

Is there a way to implement jQuery for displaying and hiding DIVs according to checkboxes in a form submitted from a separate page?

How can I achieve the functionality of submitting a form on one page, and then dynamically showing or hiding DIVs on the next page based on the checkboxes that were selected? It's also important for the script to display custom messages depending on w ...

Modifying the content within a DIV element

I want to make changes to my DIV. <div id="main"> <div id="one"> <div class="red"> ... </div> <img class="avatar" src="img/avatar1.jpg"/> <span class="name"> John < ...

What is the best way to determine if a radio button has been chosen, and proceed to the next radio button to display varied information?

The goal is to display the <div class="resp"> below each radio button when it is selected, with different content in each <div class="resp">. The previously selected <div class="resp"> should be hidden when a new radio button is chosen. O ...

The absence of the iframe in ie8 is causing problems that cannot be fixed with relative positioning

On a website, I am integrating an external 2-factor authentication solution called Duo Web using their PHP and Javascript. It works smoothly on all browsers except for IE8. When the user passes the initial login screen, the 2FA login page loads, but the if ...

Creating an animated slider using CSS styling

I am currently in the process of developing a Drupal website. One of the features on the homepage includes three images displayed side by side, each representing different news articles. My goal is to have a red transparent overlay appear on the second and ...

Find a python BeautifulSoup class name that can change dynamically

I'm working on extracting a variable class name using Python and BeautifulSoup. The specific class is a child of the "bar" class but it's located in a different div. <div class="foo"> <div class="bar"> <div class="===& ...

Animating a Bootstrap 4 card to the center of the screen

I am attempting to achieve the following effect: Display a grid of bootstrap 4 cards Upon clicking a button within a card, animate it by rotating 180 degrees, adjusting its height/width from 400px - 350px to the entire screen, and positioning it at the c ...

Unlocking the Secrets of Json Data with Knockout: A Guide

I'm struggling to create a Typewriter Effect using knockout because I can't seem to store my data inside the table properly. Despite researching for weeks, I lack the fundamental knowledge to solve this issue on my own. This is my first time seek ...

How can I align my checkboxes horizontally with a set number using bootstrap?

Is there a way to align my checkboxes next to each other in columns of 5, rather than being stacked vertically? The current layout looks like this: Checkboxes vertical I would like the checkboxes to appear like this: [x] label [x] label [x] label [x] l ...