1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

How to read value of a signal boolean in Angular17

Discussão em 'Angular' iniciado por suer231232131133, Outubro 15, 2024 às 17:23.

  1. I have a singal in service:

    export class AuthService {
    constructor(private cookieService: CookieService) {}
    url = 'http://localhost:8000/api/v1/login';
    token: string = '';
    isAuthenticated = signal<Boolean>(false);
    changeIsAAuthenticated() {
    this.isAuthenticated.set(false);
    console.log(this.isAuthenticated);
    }
    getIsAAuthenticated() {
    return this.isAuthenticated;
    }


    and in route guard i want to get its value:

    let authService = inject(AuthService);
    console.log(authService.isAuthenticated);


    and i get:

    function getter()


    How to read a value of a singal? I tried: getValue, value, get or writing a getter but it didnt work.

    console.log(authService.isAuthenticated);
    console.log(authService.getIsAAuthenticated());


    return function getter()

    I should have see the value just by console.log it, but it doesnt work.

    EDIT: i have a function:

    getIsAAuthenticated() {
    return this.isAuthenticated;
    }


    but the console log of it:

    console.log(authService.getIsAAuthenticated());


    returns:

    function getter


    so it does not work

    Continue reading...

Compartilhe esta Página