AngularJS ng-repeat img ang视频 [英] AngularJS ng-repeat img ang video

查看:56
本文介绍了AngularJS ng-repeat img ang视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何实现显示图像和视频的滑块的想法.

如何通过不同数据类型的ng-repeat进行重复?

我有一个文件列表:

var scr = [
{src: 'img1.png', title: 'Pic 1'},
{src: 'img2.jpg', title: 'Pic 2'},
{src: 'vid1.mp4', title: 'Vid 1'},
{src: 'vid2.mp4', title: 'Vid 2'}
];

可以通过ng-repeate插入图像:

<div class="slide" ng-repeat="image in images" ng-show="image.visible">
        <img src="./img/slides/{{image.src}}"/>
</div>

如何在此列表中插入视频?

  • 也许还有其他方法可以获取滑块?

我将不胜感激.

推荐答案

如果可以修改数据数组,

If you can modify the data array,

var scr = [
  {src: 'img1.png', title: 'Pic 1', type: 'imge'},
  {src: 'img2.jpg', title: 'Pic 2', type: 'imge'},
  {src: 'vid1.mp4', title: 'Vid 1', type: 'video'},
  {src: 'vid2.mp4', title: 'Vid 2', type: 'video'}
];

然后您可以使用ng-if确定要使用的元素

Then you can use ng-if to determine the element to use

<div class="slide" ng-repeat="media in scr">
  <img ng-if="media.type == 'image'" ng-src="./img/slides/{{media.src}}" />
  <video ng-if="media.type == 'video'" ng-src="{{media.src}}"></video>
</div>

这篇关于AngularJS ng-repeat img ang视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆