Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

101
Views
How do I change / show different CSS while a service is called / responds in Javascript AngularJS?

I'm trying to show a different CSS style on my HTML FORM before my code consults a service and, on its response, change it back again. I'm using ng-class to dynamically add the class whenever the activeload1 boolean is on true. Sadly this never gets reflected on my HTML. I purposely made the service call reach an exception to see if the class change happens then and it does (it just hangs on the load css since it never reaches the class deactivation due to the exception). How can I reflect the CSS class change/addition on my HTML? The code seems to just assign the true value to the activeload1 boolean consult the service and then assigning false again without reflecting anything. My code:

HTML:

<div id="divPrincipal" class="wrapper" ng-class="{loading1:bravosCtrl.activeload1}"> </div>

Snippet of funtion in JS. file:

    this.buscar = function(){            
        this.activeload1 = true;
        if (this.busqueda){
            this.usuarioService.buscarUsuario(this.busqueda,this.userSession).then((usuariosE) => {
                console.log("SUCCESS");
            });
            this.activeload1=false;
        }else{
            this.activeload1=false;
            this.searchError = true;
        }
    };

CSS :

.wrapper {
border-radius: 10px;
background: #24CDD1;
padding: 25px;
max-width: 680px;
margin: 0 auto;
margin-bottom: 20px;
box-shadow: 2px 8px 8px rgb(0 0 0 / 10%);
position: relative;
}

.wrapper.loading1::before {
content: '';
background: url('https://i.imgur.com/sdK5jNw.gif') no-repeat center center;
width: 32px;
height: 32px;
display: inline-block;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
z-index: 9999;
}
.wrapper.loading1::after {
content: '';
background: #24CDD1;
display: inline-block;
opacity: .65;
position: absolute;
width: 100%;
height: 100%;
top: 0;
left: 0;
z-index: 999;
}
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

the $http service request is asynchronous. From the code, you are assigning activeload1 to false immediately without waiting for the http response to come back.

To set activeload1 to false when the $http service respond, simply add it to the success callback function.

this.usuarioService.buscarUsuario(this.busqueda,this.userSession).then((usuariosE) => {
     console.log("SUCCESS");
     this.activeload1=false; // added here
});
      
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!