Socket
Book a DemoInstallSign in
Socket

@ng-web-apis/view-transition

Package Overview
Dependencies
Maintainers
4
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@ng-web-apis/view-transition

This is a library for declarative use of View Transition API with Angular

latest
Source
npmnpm
Version
4.12.0
Version published
Weekly downloads
43
7.5%
Maintainers
4
Weekly downloads
 
Created
Source

ng-web-apis logo View Transition API for Angular

npm version npm bundle size codecov

This service is an abstraction over view transition API for Angular

Install

npm i @ng-web-apis/view-transition

How to use

  • Import the ViewTransitionService into your Angular component or service where you want to use it.
import {ViewTransitionService} from '@ng-web-apis/view-transition';
  • Inject the ViewTransitionService into your component's constructor or with inject (Angular 14+).
// in constructor
constructor(private viewTransitionService: ViewTransitionService) {}

// via inject
viewTransitionService = inject(ViewTransitionService);
  • Use the startViewTransition method to initiate a view transition. This method takes a callback function that returns a Promise<void> or void. You can perform any necessary DOM changing logic within this callback.
startTransition() {
  this.viewTransitionService.startViewTransition(() => {
    // Your DOM changing logic goes here
    return this.animateTransition();
  }).subscribe({
    next: (transition) => {
      // Callback is done and transition is about to begin
      console.log('View transition is about to begin:', transition);
    },
    complete: () => {
      console.log('View transition completed');
    },
    error: (error) => {
      // Handle any errors that occur during the transition
      console.error('View transition error:', error);
    },
  });
}

Demo

You can try online demo here

See also

Other Web APIs for Angular by @ng-web-apis

Keywords

angular

FAQs

Package last updated on 31 Mar 2025

Did you know?

Socket

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.

Install

Related posts