Shared-element morph transitions for Angular, built on the native View Transition API. Works with any UI kit.
Degrades gracefully when the browser lacks View Transition support or the user prefers reduced motion: the DOM mutation still runs, just without the animation.
@angular/common, @angular/core; @angular/router 17+ is optional)npm install ngx-view-morph
Register the global config (optional — disables animations, e.g. for SSR or tests):
import { provideMorph } from 'ngx-view-morph';
bootstrapApplication(App, {
providers: [provideMorph({ disabled: false })],
});
For router-driven page transitions, add the router feature:
import { provideRouter } from '@angular/router';
import { provideMorphRouter } from 'ngx-view-morph/router';
provideRouter(routes, provideMorphRouter({ directionAware: true }));
Add [morph] to any element that should participate in a transition. Give matching elements in the “before” and “after” states the same name.
<mat-card [morph]="'card-' + id">…</mat-card>
Wrap the DOM mutation (state change, navigation, list update) in MorphService.run:
import { MorphService } from 'ngx-view-morph';
export class ProductListComponent {
private readonly morph = inject(MorphService);
openDetail(id: string): void {
this.morph.run(() => this.selectedId.set(id), { focusTarget: '#detail-heading' });
}
}
run returns { status, finished } — status is a signal ('running' | 'skipped' | 'done'), finished is a promise that resolves when the transition completes.
Give every item in a list the same morphClass so add/remove/reorder animations can be styled once via ::view-transition-group(.your-class):
@for (item of items(); track item.id) {
<div [morph]="'item-' + item.id" morphClass="list-item">…</div>
}
| Export | Purpose |
|---|---|
MorphDirective ([morph]) |
Assigns view-transition-name to the host element |
MorphService.run(callback, options?) |
Runs a DOM mutation (sync or async) inside a view transition |
provideMorph(config?) |
Registers global config (disabled) |
provideMorphRouter(options?) |
Enables view transitions on router navigation, optionally direction-aware |
morphDirection(fromUrl, toUrl) |
Derives 'forward' \| 'backward' from URL depth |
This is an Angular workspace containing the library (projects/ngx-view-morph) and a demo app (projects/demo) used for local development.