if Angular signals are getter functions, why can we call them?

Discussão em 'Angular' iniciado por Issac Howard, Agosto 28, 2025.

  1. Issac Howard

    Issac Howard Guest

    Take a look at the following commented code:

    export class AppComponent {
    count = 0

    // our getter function
    get itscount() {
    return this.count
    }

    // setting a function equal to a getter function
    itsCount2 = this.itscount

    func() {
    // this.itsCount2() --> error
    this.itsCount2 // --> works fine
    }
    }


    Now taking a look at Angular signals, which are also getter functions, we call them () which contradicts the previous example.

    count = signal(0)

    func() {
    console.log(this.count) // returns the function reference
    console.log(this.count()) // returns 0
    }


    Can anyone explain exactly why signals are getter functions if we call them like we call normal functions?

    Any explanation would be great!

    Continue reading...

Compartilhe esta Página