ng-if directive does not show data in AngularJS

I have a dynamic collection of images and videos that I want to display one at a time. Specifically, when I click on an image ID, I want it to show the corresponding image, and when I click on a video ID, I want it to show the relevant video.

Below is the HTML code I have implemented:

<div class="container" ng-init="image()">
        <div class="row">
            <div class="col-md-12" ng-repeat="img in images">                    
                <div class="mySlides" > 
                    <div class="numbertext">{{img.id}}</div>
                    <img class="size-i" ng-src="{{img.oe_images}}" ng-show="isActive($index)" ng-if="img.type == 'image'" type="image" style="width:100%;">
                </div>
                <video ng-if="img.type == 'video'" type="video" width="100%" ng-click="video()" id="video" controls="controls" ng-show="isActive($index)">
                    <source src="./assets/vdo/{{img.oe_images}}" type="video" type="video/mp4">
                </video>
            </div>
            <div class="row">
                <div class="col-md-12" >
                    <a class="prev" ng-click="showPrev()" style="font-size:36px;" >❮</a>
                    <a class="next" ng-click="showNext()" style="font-size:36px;" >❯</a> 
                    <div class="row paddi" >
                        <div class="column" ng-repeat="img in images">
                            <img class="demo cursor border-demo" ng-src="{{img.oe_images}}" ng-if="img.type == 'image'" type="image" ng-show="isActive($index)" style="width:100%; display: block !important;" data="{{img.id}}" ng-click="currentSlide(img.id)" alt="{{img.oe_images}}" type="image">
                        </div>
                        <video ng-if="img.type == 'video'" type="video" controls="controls" src="./assets/vdo/{{img.oe_images}}" type="video/mp4" ng-show="isActive($index)" style="width:100%"></video>
                    </div>
                </div>
            </div>
        </div>
    </div>

I utilized ng-if to display either images or videos at a time, but unfortunately, no data is being displayed after implementing this logic. Can someone please point out my mistake? Thank you in advance!

Answer №1

To enhance the structure, consider encapsulating <video> elements within <div> containers and utilize ng-show instead of ng-if for containers that do not contain <video> elements:

<div ng-show='condition1'>
     <video id='video1'/>
</div>
<div ng-show='condition2'>
     <video id='video2'/>
</div>

Answer №2

Take a look at this discussion. Specifically, pay attention to the initial response regarding the trustAsResourceUrl function. It could potentially help you resolve the issue you're facing.

app.filter("trustedUrl", ['$sce', function ($sce) {
    return function (videoUrl) {
        return $sce.trustAsResourceUrl(videoUrl);
    };
}]);

Within your HTML file:

<video src="{{ Your_URL | trustedUrl }}" videoplayer controls></video>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Converting a string to JSON format with JavaScript

My string is structured in JSON format like this: "{""c1"": ""value1"", ""c2"": ""value2""}" After storing it in an SQLITE database, I use the following Javascript code to retrieve it back as JSON: var req= "SELECT json_column from my_table"; var re ...

Counting duplicate values associated with the same key in a JSON array using JavaScript/NodeJS

Hello everyone, I could really use some assistance in solving this issue. If this has already been asked before, please direct me to the original question. Currently, I am working with a JSON array of elements. For example: var data = [{"key":"Item1"},{ ...

Custom pagination page size in AngularJS trNgGrid

I have been working on developing an Angular table using trNgGrid. It's functioning fine, but I am looking to incorporate custom pagination where the user can choose the number of page items to display per page. I checked out the TrNgGrid Global Opti ...

I am currently struggling to make the userID route parameter function correctly with react-router-relay

I've been diving into the world of React Relay and GraphQL with react-relay-router, but I'm having trouble getting the params in my routes to function correctly. Specifically, I'm struggling with the "/Maps/:userID" route. Let me share my r ...

Conceal and reveal feature for multiple dynamic identifiers simultaneously

After submitting the form, I am dynamically creating buttons. <template name="workflow"> {{#each newaction}} <div class="btn-box" > {{> actioncardsubcontent}} <button type="button" class="cancelsub" >New Action</button&g ...

The date filter in IE11 is causing a significant slowdown when used in conjunction with ng-repeat and other filters

My ng-repeat function with custom filters and a date range filter is working perfectly in Chrome, Mozilla, and Android. However, when using Internet Explorer with the Date Range filter, everything slows down significantly. It takes 10 seconds for the filte ...

What is the method for specifying a null value in Typescript?

I'm curious if this code snippet is accurate, or if there's a better way to define it. Is there an alternative to using error!? I'm unsure of its meaning and would appreciate clarification. ...

Instantly summing up two numbers with javascript

In my web development work using Visual Studio 2008, I encountered an interesting challenge. On a webpage, I have three textboxes labeled "Price," "Quantity," and "Amount." The task at hand is to calculate the value of "Amount" by multiplying the values ...

Discovering the size of an attribute in an object using Angular

I am working with a JSON object named "programs" that contains an array of key/value pairs. My task is to determine the count of objects within this array that have the key/value pair "status": "Review". In this case, there are 4 objects in total and 2 o ...

tips for asynchronously loading cloud endpoints APIs

gapi.client.load('myapi1', 'v1', function() { gapi.client.load('myapi2', 'v1', function() { gapi.client.load('myapi3', 'v1', function() { $rootscope.$broadcast( ...

How can you use Dart to uncover the content within an H1 element on an HTML webpage?

I'm currently self-teaching mobile development with Dart and Flutter, and my current project involves connecting a mobile app to a website. I want to extract the text from an H1 tag that is loaded through JavaScript on the website and display it in th ...

Deleting tasks from the to-do list using Node.js and Express with EJS

Looking to implement functionality where each list item can be removed from a Node.js array by clicking on an HTML button using EJS and Express: I am considering placing an HTML button next to each list element so that the selected element can be removed ...

The variable that contains a function is invoked, but the result is undefined

I'm having trouble with a function that should return John temp (2021) when called, but instead it's returning John undefined (undefined) const user = { username : 'John', type: 'temp', yearJoin: 2021, user ...

Resolving the issue of nested modals within Bootstrap

I am experiencing some issues with my customer visits list page. When I try to add a visit, it opens a bootstrap popup ("#Pop1") to record the visit details. Within this modal, there is an option to add a new customer on the spot, which then triggers anoth ...

Comparing time in Angular using variables

I have a time value stored in a variable that I need to compare with another one. Depending on whether my variable is greater than or less than 14:00, I want to display a response. However, I am unsure how to store the "14:00" value in the second variable ...

NodeJS is constantly refreshing the data in the database table

Every day, I use a cron job to scrape data and insert it into a database. However, I'm facing an issue where the database results on the server do not refresh themselves after new data is inserted. I've come across 2 solutions here, but one was ...

Highchart tip: How to create a scrollable chart with only one series and update the x-axis variable through drilldown

Before I pose my question, here is a link to my jsfiddle demo: http://jsfiddle.net/woon123/9155d4z6/1/ $(document).ready(function () { $('#deal_venue_chart').highcharts({ chart: { type: 'column' ...

The JavaScript slideshow fails to display an image during one rotation

The slideshow displays a sequence of images from pic1.jpg to pic8.jpg, followed by a 4-second pause with no image, and then repeats starting again at pic1.jpg. I am looking to have it loop back to pic1.jpg immediately after displaying pic8.jpg. Below is t ...

What could be the reason for the issue `injection "store" not found` showing up when attempting to call `this.store.commit()`?

I am currently working on storing values with VueX, specifically using Vuex 4.0 instead of the older version 3.0. While attempting to commit a value, I encountered an issue as follows: ... this.$store.commit("changerusername", u) ... To addres ...

Guide to smoothly scroll to a specific Label using GSAP's scrollTrigger and scrubbing within a Timeline

Currently facing an issue with a scrollTrigger Timeline where I need a button to scroll to a specific position. I attempted using seek but it did not work, and even the ScrollTo plugin lacks support for this functionality. The Timeline created using gsap ...