# Angular

Use the rupa-player custom element in an Angular component with CUSTOM_ELEMENTS_SCHEMA.

## Quick start

1. Install the player.

   ```sh
   npm i @rupamotion/player
   ```

2. Put `hero.rupaplay` (export as **Player file** in Rupamotion) in the `public` folder or the assets of your project.

3. `CUSTOM_ELEMENTS_SCHEMA` lets the template use `rupa-player`. Add it to the `schemas` of the component that uses the element (the component in step 4 has it).

4. Import the element and use it in the template:

   ```ts
   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.

## Need control?

Take the element with `@ViewChild`. Its `player` is the player once the file is mounted (`null` before):

```ts
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](/guides/control/) and [Events](/guides/events/).
