Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/typescript/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angular 当调用HostListener事件时,滚动scrollIntoView在chrome中不工作_Angular_Typescript - Fatal编程技术网

Angular 当调用HostListener事件时,滚动scrollIntoView在chrome中不工作

Angular 当调用HostListener事件时,滚动scrollIntoView在chrome中不工作,angular,typescript,Angular,Typescript,我为scroll page编写了一个函数,当我在HTML中调用这个函数(单击)时,它就是工作(在fire fox和chrome中也是如此) 但当我在类型脚本代码中调用这个函数时,它在FireFox中工作,而在chrome中不工作 @ViewChild('scrollCourse', { static: false }) scrollCourse: ElementRef; 这是我的滚动功能 async scrollToCourse() { this.desableFirstScr

我为scroll page编写了一个函数,当我在HTML中调用这个函数(单击)时,它就是工作(在fire fox和chrome中也是如此)

但当我在类型脚本代码中调用这个函数时,它在FireFox中工作,而在chrome中不工作

 @ViewChild('scrollCourse', { static: false })
 scrollCourse: ElementRef;
这是我的滚动功能

  async scrollToCourse() {
    this.desableFirstScroll=true
    await this.scrollCourse.nativeElement.scrollIntoView({ behavior: 'smooth' });
    this.desableFirstScroll=false
  }
这是HTML元素

<div #scrollCourse class="container-fluid multi-carousel kargah">
此日志返回元素信息

在滚动事件中调用函数时我的日志:

chorm <div _ngcontent-asg-c5 class=​"container-fluid multi-carousel kargah">​<div _ngcontent-asg-c5 class=​" row multi-slide-box">​…​</div>​</div>​
chorm​​…​​​

你能在stackbiltz中共享吗?我使用了很多库,所以在stackbiltz中共享很困难
@HostListener("window:scroll", ['$event'])
@HostListener("window:load", ['$event'])
getScreenSize(event?) {
 this.scrHeight = window.innerHeight;
 const number = window.pageYOffset || document.documentElement.scrollTop || window.scrollY || 0;
 // set fix kargah nav
 if (number > this.scrHeight && number < this.scrHeight + 150 && this.kargahScrollFirst) {
  if(this.desableFirstScroll == false){

    this.scrollToCourse();
    this.kargahScrollFirst = false;
  }
 }
 if ((number > (this.scrHeight + 150) || number < this.scrHeight) && !this.kargahScrollFirst) {
    this.kargahScrollFirst = true;
 }
async scrollToCourse() {
 this.desableFirstScroll=true
 await this.scrollKargah.nativeElement.scrollIntoView({ behaviour: "smooth" });
 console.log("chorm",this.scrollCourse.nativeElement);
 this.desableFirstScroll=false
}
chorm <div _ngcontent-asg-c5 class=​"container-fluid multi-carousel kargah">​<div _ngcontent-asg-c5 class=​" row multi-slide-box">​…​</div>​</div>​