【发布时间】:2017-06-28 13:02:16
【问题描述】:
Reference to the third party player on github.
问题:
如何使用 viewChild 在我的组件中获取第三方 nativescript-videoplayer 的元素引用?
错误:
当我尝试通过 this.videoPlayer.play() 访问方法播放时,我的代码编译但崩溃了
TypeError:this.videoPlayer.play 不是函数。 (在 'this.videoPlayer.play()', 'this.videoPlayer.play' 未定义)
代码:
player.component.ts
import {Component, OnInit, ViewChild} from '@angular/core';
import {registerElement} from "nativescript-angular/element-registry";
registerElement("VideoPlayer", () => require("nativescript-videoplayer").Video);
@Component({
selector: "Player",
moduleId: module.id,
templateUrl: "./player.component.html",
styleUrls: ["./player.component.css"]
})
export class PlayerComponent implements OnInit{
@ViewChild("video_player") videoPlayer: Video;
public src: string = "<YOUR VIDEO URL HERE>"
ngOnInit(): void {
this.videoPlayer.play();
}
}
player.component.html
<VideoPlayer
#video_player
[src]="src"
height="300"></VideoPlayer>
【问题讨论】:
标签: typescript nativescript angular2-nativescript