“this” cannot be used in typescript function (Angular)

后端 未结 3 514
逝去的感伤
逝去的感伤 2020-12-12 02:01

I want to reference the keyword \"this\" in a typescript class in my Angular project. But it cannot be used. I always get the error that the variable I want to change is not

3条回答
  •  孤街浪徒
    2020-12-12 02:36

    Instead of just referencing the function, you need to bind this to it: this.loggedIn.bind(this).
    Only referencing the function ' strips ' it off the this reference it has when referencing. This is standard Javascript behavior.

提交回复
热议问题