Advertisement
pepoflex

angular validar dato localStorage

Jul 10th, 2020
1,478
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // Verificar datos de localStorage (Angular)
  2. // Declaramos una Variable Global booleana
  3. agregarUsuario:boolean;
  4.  
  5. getAgregarUsuario(){
  6. if(window.localStorage.getItem('agregarUsuario') == 'false'){
  7. window.localStorage.setItem('agregarUsuario','true');
  8. // le damos el valor true:
  9. agregarUsuario = true;
  10.  
  11. }else{
  12. window.localStorage.setItem('agregarUsuario','false');
  13.  
  14. // le damos el valor false:    
  15. agregarUsuario = false;  
  16. }
  17. return window.localStorage.getItem('agregarUsuario');
  18.  
  19. // Verificar en la vista HTML
  20. <div *ngIf="agregarUsuario == true">
  21. <!-- Ocultar notificación -->
  22. </div>
  23. <div *ngIf="agregarUsuario == false">
  24. <!-- Mostrar notificación -->
  25. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement