【问题标题】:facing is not a function error, but it is on Angular面对不是功能错误,但它在 Angular 上
【发布时间】:2021-11-21 21:57:40
【问题描述】:

我正在开发一个 html、css、js 滑块,但遇到了一个奇怪的错误。 我正在研究角度

这是错误

    core.js:6479 ERROR TypeError: this.slideFunction is not a function
    at autoSlide (home.component.ts:32)
    at timer (zone.js:2561)
    at ZoneDelegate.invokeTask (zone.js:406)
    ......................................
    ......................................

这就是我的代码的样子

export class HomeComponent implements OnInit {
      counter:number = 1;
      timer: any;

      constructor() { }

      ngOnInit(): void {

        //change the current slide to the next one after 8 secondes by calling the autoSlide function
        this.timer = setInterval(this.autoSlide,8000);

      }


      autoSlide() {
       this.counter += 1;
       this.slideFunction(this.counter);
      }

      //Function that handle the change
      slideFunction(slideNumber: number): void{
   
        My logic goes there...

      }
      }

有人可以显示我在哪里做错了吗? 谢谢

【问题讨论】:

    标签: angular function setinterval


    【解决方案1】:

    您在定义之前调用slidefunction()

    先写函数,再调用。

    【讨论】:

    • 类中定义的方法顺序无关紧要
    猜你喜欢
    • 2018-03-03
    • 1970-01-01
    • 2021-07-07
    • 1970-01-01
    • 1970-01-01
    • 2017-04-28
    • 2021-07-18
    • 1970-01-01
    • 2020-09-21
    相关资源
    最近更新 更多