要解决Angular 8中使用agm-map滚动到顶部不起作用的问题,可以尝试以下解决方法:
import { ViewChild, ElementRef } from '@angular/core';
@ViewChild('agmMap') agmMap: ElementRef;
this.agmMap.nativeElement.scrollIntoView();
完整的解决方案如下所示:
import { Component, ViewChild, ElementRef } from '@angular/core';
@Component({
...
})
export class YourComponent {
@ViewChild('agmMap') agmMap: ElementRef;
scrollToTop() {
this.agmMap.nativeElement.scrollIntoView();
}
}
确保将上述代码中的"YourComponent"替换为你实际使用的组件名。
在需要滚动到顶部的地方,调用scrollToTop方法即可实现滚动到agm-map的顶部。例如,可以在按钮的点击事件中调用scrollToTop方法:
这样当按钮被点击时,agm-map将滚动到视图的顶部。