javascript - How to import video js for angular2? - Stack Overflow

I try to build an angular2 application with video js player but i don't know how to call. I try on

I try to build an angular2 application with video js player but i don't know how to call. I try on the examplepontent.html like there is not work and try in exampleponent.ts like

var videojs=require('video.js');
var player = videojs('my-player'); 

I try to build an angular2 application with video js player but i don't know how to call. I try on the example.pontent.html like there is not work and try in example.ponent.ts like

var videojs=require('video.js');
var player = videojs('my-player'); 
Share asked Jan 13, 2018 at 18:30 Akos. prestigioAkos. prestigio 371 silver badge9 bronze badges 1
  • Can you be more specific? What do you mean you don't know how to call? What do you mean when you so it does not work? Can you add the example.ponent.html code as well please? – user184994 Commented Jan 13, 2018 at 18:38
Add a ment  | 

2 Answers 2

Reset to default 3

Angular 2+ is written in TypeScript, therefore you'll need TypeScript definitions for VideoJS to be able to use the library's API properly in Angular 2. To do so, install @types/videojs via npm:

npm install @types/videojs

Now you can import VideoJS using the import statement. Also, take notice that writing pure-JS is still possible in TypeScript.

Anyway, what you're trying to achieve would probably not work because your ponent's template and logic are separated until bundling, unlike in VideoJS's example where the script is located inside of the HTML template. Therefore you'll need to pass the element itself using document.getElementById.

videojs(document.getElementById('my-player'));

I suggest you to refer to this example of a VideoJS Angular 2 ponent.

Simple steps: 1. npm install --save video.js 2. npm install --save-dev @types/video.js

After installation just import like this. Now we can use interfaces too like this.

 import * as videojs from 'video.js'

 class VideoComponent {
     public videoJS = videojs.default
     private videoPlayer: videojs.VideoJsPlayer
     private options: videojs.VideoJsPlayerOptions

     someMethod() {
        this.videoJS('my-player', {
          controls: true,
          autoplay: true,
          preload: 'auto'
        });

      }

 }

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744857577a4597498.html

相关推荐

  • javascript - How to import video js for angular2? - Stack Overflow

    I try to build an angular2 application with video js player but i don't know how to call. I try on

    2天前
    50

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信