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

151
Views
Objeto de promesa de devolución angular del servicio. Intentando acceder al valor para cambiar la directiva ng-if

He visto problemas similares a este, pero espero que alguien me pueda ayudar.

Estoy tratando de verificar que un usuario haya iniciado sesión y modifique el html para un botón de inicio de sesión o cierre de sesión.

 this.getUser = function(){ return $http.get('/api/user'); };

Servicio

 vm.user = function() { dataService.getUser().then(function(res){ if(res.data.userId.length){ return true; }else{ return false; } }); }

controlador

 <li class="nav-item" ng-hide='vm.user()'> <a class="nav-link" href="/api/signin">Sign in</a> </li>

He probado diferentes variaciones de esto en vano. Estoy devolviendo un objeto de promesa o no puedo usar la variable fuera de la promesa. Gracias

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Simplemente use la variable en lugar de ver la función completa en la directiva ng-hide. Busque el fragmento de código.

Archivo del controlador:

 vm.flags = {}; vm.user = function() { dataService.getUser().then(function(res){ if(res.data.userId.length){ vm.flags.isUserLoggedIn = true; }else{ vm.flags.isUserLoggedIn = false; } }); }

archivo html

 <li class="nav-item" ng-hide='vm.flags.isUserLoggedIn'> <a class="nav-link" href="/api/signin">Sign in</a> </li>
about 4 years ago · Santiago Trujillo 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!