I am playing around with angularjs and have run into what seems like it should be a trivial issue with data binding and HTML 5.
Let's say I have an array that represents a mix of image and video files:
.controller('Foo', ['$scope', function($scope) {
$scope.photos = [
{
Url: "img/2011-04-30\ 16.51.38.jpg",
},
{
Url: "img/2011-04-30\ 16.51.53.jpg",
},
{
Url: "img/2011-04-30\ 17.35.58.jpg",
},
{
Url: "img/video-2011-04-30-16-52-23.mp4",
},
{
Url: "img/video-2011-04-30-18-01-42.mp4",
},
{
Url: "img/2011-04-30\ 16.51.47.jpg",
},
{
Url: "img/2011-04-30\ 16.52.40.jpg",
},
{
Url: "img/2011-04-30\ 18.02.26.jpg",
},
{
Url: "img/video-2011-04-30-17-36-02.mp4",
},
]}]);
I want to turn this array of urls into a mixed media slideshow so I am trying to set up an ng-repeat loop over the array and bind the data to <img> and <video> tags.
Obviously this is not going to produce what I want but here is my sample hg-repeat loop:
<div ng-controller="Foo" ng-repeat = "photo in photos">
<img ng-src="{{ photo.Url }}" class="photos" width="200" height="200" />
<video src="{{ photo.Url }}" class="video" controls/>
Each iteration through the loop I want either an OR a but not both. One option is to create an array of html tags in the controller and use that array as the source of the ng-repeat but that is blurring the line between view and controller which does not feel right.
Is there a way to handle this natively in Angularjs?
img/video-...mp4in a property called$scope.photosshould be a flag that you're going about things inefficiently.