
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
@avtest/ng-spy
Advanced tools
A lightweight, dependency-free scrollspy for angular. Use this library to spy on HTML elements on your page when the window is scrolled or resized.
A lightweight, dependency-free scrollspy for angular. Use this library to spy on HTML elements on your page when the window is scrolled or resized.
This library provides directives and services to help you subscribe to new elements entering the browser window and possibly adds or remove CSS classes to these elements.
This library does not provide utilities to scrollTo spied elements and certainly does not handle link clicks. You have to handle these on your own.
Code for the previous example is also in this repository under the src folder.
npm install --save ng-spy
Import the module
@NgModule({
declarations: [],
imports: [
// ...
ScrollSpyModule
],
providers: [],
bootstrap: [AppComponent]
})
export class AppModule { }
In your container component:
ngAfterViewInit() {
this.spyService.spy({ thresholdBottom: 50 });
}
Use SpyTarget directive to mark element as a target:
<h1 spyTarget="target-1">Hello, World!!</h1>
Optional: Use SpyOn directive to spy on a target:
<a spyOn="target-1" activeClass="navbar__link--active" class="navbar__link" href="#target-1">target 1</a>
Alternatively, you can subscribe to activeSpyTarget from ScrollSpyService, which will emit every time a new element is active.
this.scrollspyService.activeSpyTarget.subscribe(
(activeTargetName: string) => console.log(activeTargetName)
);
To start multiple spys you can scope the ScrollSpyService to a specific component or module in the providers array.
// In component or module metadata:
{
// ...
providers: [ ScrollSpyService ]
}
SpyOnA directive to spy on a previously added target.
| Name | Type | Description | Default value |
|---|---|---|---|
| activeClass | string | a class to be added to host element if it is active | |
| spyOn | string | the name of the target to spy on |
SpyTargetA directive to mark an element as a spy target.
| Name | Type | Description | Default value |
|---|---|---|---|
| spyTarget | string | the name of the target to be added. This also adds an id attribute to the host element with the spyTarget value |
ScrollSpyServicespy(spyOptions: SpyOptions): voidStarts spying on the targets. Call this on the top level container of your targets in AfterViewInit lifecycle hook. Without calling this function, nothing will happen.
Parameters:
| Name | Type | Optional? | Description | Default value |
|---|---|---|---|---|
| spyOptions | SpyOptions | Yes | Options to override some default behaviors. See SpyOptions for more details. | { thresholdTop = 0 , thresholdBottom = 0 } |
addTarget(target: SpyTarget): voidadds the target to the targets collection for spying. This action will also trigger a check to re-evaluate the active target.
Parameters:
| Name | Type | Optional? | Description | Default value |
|---|---|---|---|---|
| target | SpyTarget | No | The target to be added. |
removeTarget(target: string): voidRemoves a previously added target from the targets collection. This action will also trigger a check to re-evaluate the active target.
Parameters:
| Name | Type | Optional? | Description | Default value |
|---|---|---|---|---|
| target | string | No | The target name to be removed |
checkActiveElement(scrollContainer?: ElementRef): voidTries to find the active target in the targets collection. If found it will emit the target name using the activeSpyTarget observable, Otherwise it will emit null.
Parameters:
| Name | Type | Optional? | Description | Default value |
|---|---|---|---|---|
| scrollContainer | ElementRef | Yes | The scroll container in which your targets are present. |
isElementActive(element: ElementRef, scrollContainer?: ElementRef, currentActiveElement?: ElementRef): booleanChecks if the element is inside the browser window and optionally inside the scrollContainer.
If a currentActiveElement is provided, it will also check if the element's offsetTop is greater than the currentActiveElement. Meaning, if two targets are active, only the last one on the screen will be emitted.
If a scrollContainer is provided, it will ignore thresholdBottom and thresholdTop in the window check and will instead check for the threshold inside the scrollContainer.
Parameters:
| Name | Type | Optional? | Description | Default value |
|---|---|---|---|---|
| element | ElementRef | No | The element to be checked. | |
| scrollContainer | ElementRef | Yes | The scroll container which the element is inside. | |
| currentActiveElement | ElementRef | Yes | An element that is guaranteed to be active. |
stopSpying(): voidStops spying on the targets, completes the activeSpyTarget subject and clears the targets collection.
activeSpyTarget: Observable<string>Use this to subscribe to new active spy targets. Value can be null if no target is found to be active.
SpyOptions| Name | Type | Optional? | Description |
|---|---|---|---|
| scrollContainer | ElementRef | Yes | The scroll container in which your targets are present. |
| thresholdTop | number | Yes | A number added to the top of your scroll container while checking in isElementActive |
| thresholdBottom | number | Yes | A number added to the bottom of your scroll container while checking in isElementActive |
SpyTarget| Name | Type | Optional? | Description |
|---|---|---|---|
| name | string | No | The name of the spy target. This is also may be used as an id for the html element. So make sure this is unique. |
| element | ElementRef | No | A reference to the target element. |
RESIZE_TIME_THRESHOLDUsed in the resize event with auditTime.
Default Value: 300
SCROLL_TIME_THRESHOLDUsed in the scroll events with auditTime.
Default Value: 10
FAQs
A lightweight, dependency-free scrollspy for angular. Use this library to spy on HTML elements on your page when the window is scrolled or resized.
We found that @avtest/ng-spy demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.