Question:
How do I get @vimeo/player to work on my Angular2/Typescript project (specifically Ionic2) ?
Description:
Trying to get the vimeo player to work with Angular2/Typescript.
npm install --save @vimeo/player
According to their documentation the library can be used like so:
If you’re using a module bundler like webpack or rollup, the exported object will be the Player constructor (unlike the browser where it is attached to window.Vimeo):
import Player from '@vimeo/player';
const player = new Player('handstick', {
id: 19231868,
width: 640
});
player.on('play', function() {
console.log('played the video!');
});
Which looks super promising ! But doesn't work.
What I've tried:
I've installed @vimeo/player
and @types/vimeo__player
I created a player component in my Ionic2 app.
player.ts:
import {Component, ViewChild} from '@angular/core';
import {NavController} from "ionic-angular/index";
//noinspection TypeScriptCheckImport,TypeScriptCheckImport
import Player from "@vimeo/player";
@Component({
selector: 'player-component',
templateUrl: 'player.html'
})
export class PlayerComponent {
@ViewChild('player_container') playerContainer;
private player: Player;
constructor(public navCtrl: NavController){}
ngAfterViewInit() {
// child is set
this.player = new Player(this.playerContainer);
console.log(Player);
}
}
I use view child, but I've also tried with the element's ID.
player.html
<div #player_container></div>
And get the following error:
Uncaught (in promise): TypeError: You must pass either a valid element or a valid id. Player@http://localhost:8100/build/main.js:102846:32 ngAfterViewInit@http://localhost:8100/build/main.js:74715:80 callProviderLifecycles@http://localhost:8100/build/main.js:11417:33 callElementProvidersLifecycles@http://localhost:8100/build/main.js:11392:35 callLifecycleHooksChildrenFirst@http://localhost:8100/build/main.js:11376:47 checkAndUpdateView@http://localhost:8100/build/main.js:12408:36 callWithDebugContext@http://localhost:8100/build/main.js:13462:47 detectChanges@http://localhost:8100/build/main.js:10474:81 _viewAttachToDOM@http://localhost:8100/build/main.js:43884:53 _transition@http://localhost:8100/build/main.js:43976:34 onInvoke@http://localhost:8100/build/main.js:4406:43 run@http://localhost:8100/build/polyfills.js:3:4146 http://localhost:8100/build/polyfills.js:3:13734 onInvokeTask@http://localhost:8100/build/main.js:4397:47 runTask@http://localhost:8100/build/polyfills.js:3:4841 o@http://localhost:8100/build/polyfills.js:3:1898 invoke@http://localhost:8100/build/polyfills.js:3:10674
As you can see it compiles but crashes at runtime.
@types/vimeo__player Just doesn't seem to be finished, and doesn't even seem to be noticed when I import @vimeo/player
The issue on github regarding vimeo__player seems show that this is true.
It looks like module resolution is correctly resolving it as a JS module, but only because it didn't find the types first. Are you sure you've correctly included those types? --listFiles would show you if it's lincluded.