![Introducing Enhanced Alert Actions and Triage Functionality](https://cdn.sanity.io/images/cgdhsj6q/production/fe71306d515f85de6139b46745ea7180362324f0-2530x946.png?w=800&fit=max&auto=format)
Product
Introducing Enhanced Alert Actions and Triage Functionality
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
@ng-web-apis/intersection-observer
Advanced tools
Readme
This is a library for declarative use of Intersection Observer API with Angular.
If you do not have @ng-web-apis/common:
npm i @ng-web-apis/common
Now install the package:
npm i @ng-web-apis/intersection-observer
Import IntersectionObserverModule
for directives to work
Create IntersectionObserver with
waIntersectionObserver
directive
Observe elements with waIntersectionObservee
directive
Optional: provide root element with waIntersectionRoot
directive and use waIntersectionThreshold
and
waIntersectionRootMargin
attributes to configure
IntersectionObserver options
NOTE: Keep in mind these are used one time in constructor so you cannot use binding, only strings. Pass comma separated numbers to set an array of thresholds.
Observing multiple elements intersecting with viewport using single observer
<section
waIntersectionObserver
waIntersectionThreshold="0.5"
>
<div (waIntersectionObservee)="onIntersection($event)">I'm being observed</div>
<div (waIntersectionObservee)="onIntersection($event)">I'm being observed</div>
</section>
Observing elements intersecting with parent element, each having different configuration therefore using individual observers:
<section waIntersectionRoot>
<div
waIntersectionObserver
waIntersectionThreshold="0.5"
(waIntersectionObservee)="onIntersection($event)"
>
I'm being observed
</div>
<div
waIntersectionObserver
waIntersectionThreshold="1,0.5,0"
(waIntersectionObservee)="onIntersection($event)"
>
I'm being observed
</div>
</section>
Alternatively you can use Observable
-based services:
IntersectionObserveeService
can be used to observe elements under waIntersectionObserver
directive in the DI tree
IntersectionObserverService
can be used to observe single element independently. Provide tokens manually to
configure it:
@Component({
selector: 'my-component',
providers: [
IntersectionObserverService,
{
provide: INTERSECTION_THRESHOLD,
useValue: 0.5,
},
{
provide: INTERSECTION_ROOT_MARGIN,
useValue: '10px',
},
],
})
export class Example {
constructor(@Inject(IntersectionObserverService) entries$: IntersectionObserverService) {
entries$.subscribe(entries => {
// Don't forget to unsubscribe
console.log(entries);
});
}
}
In this case provide
INTERSECTION_ROOT
up the DI tree if you want to observe intersection with a particular parent element
![]() | ![]() | ![]() | ![]() |
---|---|---|---|
15+ | 55+ | 51+ | 12.2+ |
You can use polyfill to support older browsers
If you want to use this package with SSR, you need to mock IntersectionObserver
class on the server. You can use our
Universal package for this, see
this example.
You can try online demo here
Other Web APIs for Angular by @ng-web-apis
FAQs
A library for declarative use of Intersection Observer API with Angular
The npm package @ng-web-apis/intersection-observer receives a total of 15,644 weekly downloads. As such, @ng-web-apis/intersection-observer popularity was classified as popular.
We found that @ng-web-apis/intersection-observer demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 0 open source maintainers 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.
Product
Socket now supports four distinct alert actions instead of the previous two, and alert triaging allows users to override the actions taken for all individual alerts.
Security News
Polyfill.io has been serving malware for months via its CDN, after the project's open source maintainer sold the service to a company based in China.
Security News
OpenSSF is warning open source maintainers to stay vigilant against reputation farming on GitHub, where users artificially inflate their status by manipulating interactions on closed issues and PRs.