这个问题可能更普遍,只是在Nativescript移动应用程序中包含NPM插件,但我将使用这个特定的插件作为示例 . 我已经按照文档添加了来自Nativescript网站的第三方插件,但我似乎仍然无法使用Angular 2和Nativescript将此插件与我的移动应用程序一起使用 .
我使用以下方法安装了插件:
tns plugin add nativescript-videoplayer
这是我的组件:
import { Component, ElementRef, ViewChild } from "@angular/core";
import { Video } from 'nativescript-videoplayer';
@Component({
selector: "grandhall",
templateUrl: "pages/grandhall/grandhall.html",
styleUrls: ["pages/grandhall/grandhall-common.css", "pages/grandhall/grandhall.css"]
})
export class GrandHallComponent {
}
这是我的模板:
<StackLayout>
<Label text="Grand Hall"></Label>
<VideoPlayer:Video id="nativeVideoPlayer" controls="true" autoplay="true" height="280" src="https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4" />
</StackLayout>
这就是我在移动应用程序中显示视频时需要做的插件文档,但视频没有显示在页面上 . 我也在iPhone 6 Plus的实际设备上进行测试,而不是在模拟器中进行测试 .
我猜我需要做一些不同的事情来包含我的Angular 2模板中的插件视图 . 请帮忙 .
1 回答
你需要像这样调用
registerElement
:// somewhere at top of your component or bootstrap file import {registerElement} from "nativescript-angular/element-registry"; registerElement("VideoPlayer", () => require("nativescript-videoplayer").Video);
然后它可以在您的UI和NativeScript Angular文档中使用:https://docs.nativescript.org/angular/plugins/angular-third-party.html#simple-elements