MCPcopy Create free account
hub / github.com/angular/angular / scroll

Method scroll

adev/src/app/app-scroller.ts:91–119  ·  view source on GitHub ↗
(injector?: Injector)

Source from the content-addressed store, hash-verified

89 }
90
91 private scroll(injector?: Injector) {
92 if (!this._lastScrollEvent || !this.canScroll) {
93 return;
94 }
95 // Prevent double scrolling on the same event
96 this.canScroll = false;
97 const {anchor, position} = this._lastScrollEvent;
98
99 // Don't scroll during rendering
100 const ref = afterNextRender(
101 {
102 write: () => {
103 if (position) {
104 this.viewportScroller.scrollToPosition(position);
105 } else if (anchor) {
106 this.viewportScroller.scrollToAnchor(anchor);
107 } else {
108 this.viewportScroller.scrollToPosition([0, 0]);
109 }
110 },
111 },
112 // Use the component injector when provided so that the manager can
113 // deregister the sequence once the component is destroyed.
114 {injector: injector ?? this.injector},
115 );
116 this.cancelScroll = () => {
117 ref.destroy();
118 };
119 }
120}

Callers 3

onClickMethod · 0.45
forceTooltipScrollTopFunction · 0.45

Calls 4

afterNextRenderFunction · 0.90
destroyMethod · 0.65
scrollToPositionMethod · 0.45
scrollToAnchorMethod · 0.45

Tested by

no test coverage detected