我正在將我的角度2項目從systemjs轉換爲角度cli。我刪除了index.html中的所有js和css文件,並在angular-cli.json中包含了所有文件和videojs css和js文件, 項目正確編譯,但執行中出現錯誤「videojs未定義」, 我沒有看到錯誤,如果我在index.html 包含videojs文件,你能幫我一把。如何解決角度cli中的這個錯誤?錯誤參考錯誤:在角度cli中'videojs未定義'?
角cli.json文件
{
"$schema": "./node_modules/@angular/cli/lib/config/schema.json",
"project": {
"name": "angular-cli-project"
},
"apps": [{
"root": "src",
"outDir": "dist",
"assets": [
"assets",
"favicon.ico"
],
"index": "index.html",
"main": "main.ts",
"polyfills": "polyfills.ts",
"test": "test.ts",
"tsconfig": "tsconfig.app.json",
"testTsconfig": "tsconfig.spec.json",
"prefix": "app",
"styles": [
"styles.css",
"./assets/admin/pages/css/lock.css",
"./assets/css/dashboardPage.css",
"./assets/css/facebook.css",
"./assets/css/form.errors.css",
"./assets/js/videoCapturing/videojs.record.min.css",
"./assets/js/videojs/video-js.css",
],
"scripts": [
"./assets/js/videojs/video.min.js",
"./assets/js/videoCapturing/RecordRTC.js",
"./assets/js/videojsvideojs.record.js",
"./assets/js/videojs/videojs-contrib-hls.js",
"./assets/js/videojs/videojs.hotkeys.min.js",
],
"environmentSource": "environments/environment.ts",
"environments": {
"dev": "environments/environment.ts",
"prod": "environments/environment.prod.ts"
}
}],
"e2e": {
"protractor": {
"config": "./protractor.conf.js"
}
},
"lint": [{
"project": "src/tsconfig.app.json"
},
{
"project": "src/tsconfig.spec.json"
},
{
"project": "e2e/tsconfig.e2e.json"
}
],
"test": {
"karma": {
"config": "./karma.conf.js"
}
},
"defaults": {
"styleExt": "css",
"component": {}
}
}
組件代碼:
import {Component,OnInit, OnDestroy } from '@angular/core';
declare var videojs :any;
@Component({
selector: 'app-play-video',
templateUrl: './play-video.component.html',
styleUrls : []
})
export class PlayVideoComponent implements OnInit{
public videoJSplayer :any;
ngOnInit() {
this.videoJSplayer = videojs(document.getElementById('example_video_11'), {}, function() { // here videojs is undefined.
this.play();
}
}
}
播放video.component.html:
<video id="example_video_11" class="video-js vjs-default-skin vjs-big-play-centered"
controls preload="auto" width="640" height="264"
poster="http://video-js.zencoder.com/oceans-clip.png"
data-setup='{"example_option":true}'>
</video>
如果您打開chrome控制檯並嘗試'videojs'它是未定義的? –
是的,我看到console.videojs中的錯誤是未定義的 –