Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

104
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda