Angular error this.mymethod is not a function

前端 未结 2 1073
灰色年华
灰色年华 2021-01-24 22:12

I\'m trying to create an image slider inside my Angular 5 component. The slider has Previous and Next controls which both work fine but I can\'t get it to slide automatically.

2条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-24 22:51

    change

    setTimeout(this.autoslide, 2000)
    

    to

    setTimeout(this.autoslide.bind(this), 2000)
    

    for this to keep pointing to the current class instance.

提交回复
热议问题