AngularJS ng-class to remove a class

I am currently dealing with a frustrating issue caused by the following code

<input type="text" ng-class="GLOBAL_ERROR == 1 ? 'error-branch' : 'defaulttxt'" ng-model="frm.FirstName" name="FN" ng-required="true" ng-minlength="2" ng-maxlength="100"/>

Upon page load, the form is invalid and thus has the class error-branch. However, after data is loaded, the class remains as error-branch.

How can I resolve this? Should I implement something like the following?

$scope.$on('$viewContentLoaded', function(){

  });

Answer №1

Big shoutout to @dfsq for helping me uncover the solution by recreating the problem on plunkr

The key is to include an additional condition to check if GLOBAL_ERROR ==1 and also

GLOBAL_ERROR==1 && myForm.FN.$invalid

Issue resolved once and for all! Amazing!

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

What is the best way to align a value within CardActions in Material UI?

I'm currently facing an issue with my website design. Here's a snapshot of how it looks: https://i.sstatic.net/UuBJJ.png Additionally, here is the code snippet related to the problem: <CardActions> <Typography style={{ fon ...

Can you define the "tab location" in an HTML document using React?

Consider this component I have: https://i.stack.imgur.com/rAeHZ.png React.createClass({ getInitialState: function() { return {pg: 0}; }, nextPage: function(){ this.setState({ pg: this.state.pg+1} ) }, rend ...

Is it possible to modify data in a different view using an AngularJS Directive?

Hey there, I have quite a complex question to ask and I'm not sure if my approach is correct. If it's not, please feel free to guide me in the right direction. So, I've created a directive for a navigation bar. I've managed to make it ...

"Customized Bootstrap button featuring a tooltip and modal, experiencing incorrect padding within the button group design

I encountered an issue with a button-group containing 2 buttons, each with a tooltip and a modal. Bootstrap recommends wrapping the buttons with spans to manage two "data-bs-toggle" attributes, which is what I initially did. While the functionality works ...

How to activate a window that's been minimized in Chrome

I am experiencing an issue with a button that is supposed to open a new window as a popup below the parent page. It works correctly in IE and Firefox, but in Chrome, the popup appears on top of the parent window. Can someone please provide a solution? Fo ...

Using AJAX for fetching and saving an object into a variable

I am dealing with two specific files in my project. The first one is called index.php, where the user initiates an AJAX request. The second one is called process.php, which is responsible for sending data back to the index.php file. function AjaxResponse( ...

MongoSearch: A Geo-Targeted Search Engine tailored to your needs

For my new app project, I am using MongoDB, Express, JS, and Node to create a platform similar to Yelp. After some research, I discovered how to search for multiple fields within a campus schema (including campuses, restaurants, barbershops, and names). No ...

Troubleshooting: Issue with Dependency Injection functionality in Angular 2 starter project

I’ve encountered a strange error whenever I attempt to inject any dependency TypeError: Cannot set property 'stack' of undefined at NoProviderError.set [as stack] (errors.js:64) at assignAll (zone.js:704) at NoProviderError.ZoneAwareError (zon ...

Progressive JQuery Ajax Requests

I'm attempting to retrieve specific information from a webpage, such as the title of the page and the domain name, and then perform an asynchronous POST request using jQuery with that extracted data. However, I've encountered an issue where my Ja ...

PNG can only be adjusted to a smaller size using IMG-Responsive, as opposed to scaling from small to large

I'm facing an issue when trying to adjust the size of a PNG image with a transparent background that has a width of 279 pixels and height of 432 pixels, using the img-responsive class in Bootstrap3. The Issue: Every time I attempt to upload the pn ...

Utilizing Airbnb's iCalendar Link for Automation

I have obtained the iCalendar link for an Airbnb listing. Upon visiting the link in any browser, it automatically triggers the download of a .ics iCalendar file. My goal is to develop an application that can sync with this specific Airbnb listing's iC ...

jQuery Slider Showing Incorrect Images

My jQuery slider is acting strangely. It hides the first image, shows the second one, but then just repeats the cycle by showing the first image again instead of loading the third one. I'm puzzled about what could be causing this issue in my code. Do ...

The Bootstrap image slider is limited to showing a single item at a time

I've been attempting to implement a carousel in Bootstrap 4 that displays multiple items at once and allows scrolling one item at a time, but I can't seem to get it right. Despite going through various tutorials and forum posts, the carousel alwa ...

The custom confirmation popup is experiencing technical issues

Currently, I am utilizing a plugin to modify the appearance of the confirm popup. Although I have successfully customized the confirm popup, I am encountering an issue where upon clicking the delete icon, the custom confirm popup appears momentarily before ...

Secure your DOM's href attribute from prying eyes

I have a display page that shows all of our reports in the following format: https://i.sstatic.net/lNzH8.png When hovering over a report, it displays the file's URL (where it is located on our server). I want to prevent users from accessing this inf ...

CSS rule for targeting an element that does not have any child elements

I have a variety of different elements that are structured similarly to the following.. <div id="hi"> <div class="head"> </div> <div class="footer"> </div> </div> ..however, some of these elements do no ...

Showing a message only when there is input in the search bar using jQuery

I'm currently working with a Google Instant style search script that is written in jQuery and queries a PHP file. The issue I am facing is that even when the search box is empty and there are no search terms, the script still displays a message saying ...

Ways to retrieve a specific Array[property] within an object?

I am struggling to access a specific property within an array of objects. My goal is to extract the "name" elements from the app catalog array, combine them with the names from the custom array apps.name, and assign the result to a new property in the ques ...

Issue with videos not playing and difficulty navigating through hyperlinks

Here is the link to my webpage (for preview of my code): I am using Bootstrap 4 for my project. Everything works fine, but I am facing two small issues with the Cookies Box: The animation moves from left to right (which is correct) - but then it returns ...

Retrieving the selected value from a dropdown menu before it is altered using vanilla JavaScript

I am trying to implement a feature where the previous value of a dropdown is captured when it is changed. Essentially, I need to compare the previous and current values of the dropdown and perform an action based on that information. For example, if Option ...