Angular
Copy as MarkdownQuick start
Section titled “Quick start”-
Install the player.
Terminal window npm i @rupamotion/player -
Put
hero.rupaplay(export as Player file in Rupamotion) in thepublicfolder or the assets of your project. -
CUSTOM_ELEMENTS_SCHEMAlets the template userupa-player. Add it to theschemasof the component that uses the element (the component in step 4 has it). -
Import the element and use it in the template:
import { Component, CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";import "@rupamotion/player/element";@Component({selector: "app-hero",schemas: [CUSTOM_ELEMENTS_SCHEMA],template: `<rupa-player src="/hero.rupaplay"></rupa-player>`,})export class HeroComponent {}
That’s it: the animation plays.
This demo loads a .rupaplay file: it plays once JavaScript runs.
Need control?
Section titled “Need control?”Take the element with @ViewChild. Its player is the player once the file is mounted (null before):
import { Component, CUSTOM_ELEMENTS_SCHEMA, ElementRef, ViewChild } from "@angular/core";import "@rupamotion/player/element";import type { RupaPlayerElement } from "@rupamotion/player/element";
@Component({ selector: "app-hero", schemas: [CUSTOM_ELEMENTS_SCHEMA], template: ` <rupa-player #hero src="/hero.rupaplay"></rupa-player> <button (click)="pause()">Pause</button> `,})export class HeroComponent { @ViewChild("hero") hero?: ElementRef<RupaPlayerElement>;
pause() { this.hero?.nativeElement.player?.pause(); }}See Control playback and Events.