【发布时间】:2017-12-02 21:23:14
【问题描述】:
这就是我想要实现的目标。每当用户点击另一个component 时,我都会尝试更新component 中的值。看看我的代码
这是我的app.component.html 文件
<div class="col-sm" *ngFor="let tabs of videoTabs">
<!-- this is where i want the user to click on -->
<div class="tabs hvr-back-pulse">
<div class="row">
<div class="text-center col-sm-4">
<img src="{{ tabs.image }}" class="rounded-circle img-thumbnail">
</div>
<div class="col-sm-8">
<small>{{ tabs.title }}</small>
<p>{{ tabs.description }}</p>
</div>
</div>
</div>
<!-- eof click container -->
</div>
这是我的app.component.ts 文件 *****已更新******
import { Component, EventEmitter } from '@angular/core';
import { VideoTab } from './videotab.model'; //importing our video class so we can use it
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styleUrls: ['./app.component.scss']
})
export class AppComponent {
videoTabs: VideoTab[];
// when angular creates a new instance of this componenet,
// it calls the constructor function
constructor() {
this.videoTabs = [
new VideoTab(
'https://videosrc.video.net/video.png',
'test',
'test',
'test'
),
new VideoTab(
'https://1111111.cloudfront.net/landingpage.mp4',
'test',
'test',
'test'
),
]
}
setCurrentTab(tab: VideoTab): void {
this.currentTab = tab;
}
}
videotab.model.ts文件
/**
* Provides a Video object
*/
export class VideoTab {
constructor(
public image: string,
public description: string,
public title: string,
public videoSrc: string
) {}
}
这是我希望组件在 src attribute 上更新我的 video tag 中的值的地方 ****更新为使用 VIDEO.JS********
<video id="background" class="video-js" loop controls preload="auto" width="100%" height="100%" poster="" data-setup="{}">
<source [src]="currentTab?.videoSrc" type='video/mp4'>
</video>
现在我的视频标签不在它自己的组件中,它目前在我的标签所在的app.component.html 文件中。感谢所有的帮助。我正在阅读一本关于如何开发 Angular 2 应用程序的书,所以这对我来说仍然是新的。再次感谢大家的帮助!!!
**** 已更新 ****
使用选项卡动态加载 src 属性时,我从 video.js 收到以下错误消息
VIDEOJS: ERROR: (CODE:4 MEDIA_ERR_SRC_NOT_SUPPORTED) The media could not be loaded, either because the server or network failed or because the format is not supported. 当我在新选项卡中加载带有 mp4 文件的云端链接时,一切都加载正常。感谢大家的帮助
【问题讨论】:
-
由于您是 Angular 2 的新手,请允许我将您重定向到 Multiple components interaction in Angular 2。我认为一个完整的教程将帮助您而不是论坛上的几个用户。
-
非常感谢!!因为我一直在关注这本书,所以没有看过文档。期待@tricheriche
-
那么你应该,它是一个真正的金矿。我实际上在浏览器中固定了教程选项卡,以便快速访问它!
标签: angular ecmascript-6 components