Refreshin the attached DOM to a directive without a page reload

Within a directive, I have implemented some text and a video tag in the code below:


app.directive('ngAzuremediaplayer', function () {
    return {
        restrict: 'AE',
        priority: 10,
        link: function (scope, elem, attrs) {
            scope.hideapprove = attrs.hideapprove;
            scope.hidereject = attrs.hidereject;
            scope.hideinfo = attrs.hideinfo;
            scope.hidedelete = attrs.hidedelete;
            scope.hidecard = attrs.hidecard;
            scope.hidethumb = attrs.hidethumb;

            scope.$watch(attrs.ngBind, function (newvalue) {
                var myOptions = {
                    "nativeControlsForTouch": false,
                    "logo": { "enabled": false },
                    controls: true,
                    autoplay: false,
                    poster: scope.video.ThumbnailUri,

                }
                var myPlayer = null;
                if (scope.video.AMSUri != null) {
                    myPlayer = amp(document.getElementById(scope.video.RowKey), myOptions);
                    myPlayer.src([
                        {
                            "src": scope.video.AMSUri,
                            "type": "application/vnd.ms-sstr+xml"
                        }
                    ]);
                }
                else {
                    if (scope.video.RawVideoUri != null) {
                        myPlayer = amp(document.getElementById(scope.video.RowKey), myOptions);
                        myPlayer.src([
                            {
                                "src": scope.video.RawVideoUri,
                                "type": "video/mp4"
                            }
                        ]);
                    }
                }
            });
        },
        templateUrl: '/app/templates/VideoControl.html',
    }
});

Below is the template file used:

<div class="monster-admin-video monster-section-link">
<div class="monster-card">
    <div class="monster-card-content" ng-hide="hidecard">
        <h5 class="monster-card-title" style="margin-top: 0px;">{{video.ChannelName}}</h5>
    </div>
    <div class="monster-admin-video-player embed-responsive embed-responsive-16by9" id="">
        <video id="{{video.RowKey }}" class="azuremediaplayer amp-default-skin amp-big-play-centered embed-responsive-item" controls>
            <p class="amp-no-js">
                To view this video please enable JavaScript, and consider upgrading to a web browser that supports HTML5 video
            </p>
        </video>
    </div>
    <div class="monster-admin-action-buttons">
        <a class="btn btn-success btn-sm" ng-hide="hideapprove" ng-click="vm.approve(video)"><i class="fa fa-check-circle-o fa-lg"></i></a>
        <a class="btn btn-info btn-sm" ng-hide="hideinfo" ng-click="vm.info(video)"><i class="fa fa-info-circle fa-lg"></i></a>
        <a class="btn btn-danger btn-sm" ng-hide="hidedelete" ng-click="vm.delete(video)"><i class="fa fa-trash fa-lg"></i></a>
        <a class="btn btn-default btn-sm" ng-hide="hidethumb" ng-click="vm.createThumbnail(video)"><i class="fa fa-camera fa-lg"></i></a>
    </div>
    <div class="monster-admin-video-caption">
        <div style="float:left">
            {{video.EncodingStatus}}
        </div> <div style="float:right">
            {{video.VideoProgress}}
        </div>
        <br />
        <p class="lead monster-admin-video-title" ng-bind="video.Title" data-ellipsis></p>
        <p class="monster-admin-video-desc" ng-bind="video.Description" data-ellipsis></p>
    </div>
</div>

I am looking to update EncodingStatus and VideoProgress on an interval. The following function in regular JavaScript carries out this task:


function populateVideoStatus(data) {
    angular.forEach(data, function (video, key) {
        if (document.getElementById(video.RowKey) != null) {
            var encodingStatus = "";
            var videoProgress = ""
            switch (video.VideoStatusId) {
                case 0:
                    video.EncodingStatus = "Video Not Uploaded";
                    break;
                case 1:
                    video.EncodingStatus = "Video Uploading";
                    break;
                // Additional cases for different statuses...
            }

            if (video.VideoProgress == "100%") {
                video.VideoProgress = "";
            }

            var videoPlayer = document.getElementById(video.RowKey);
            var temp = videoPlayer.parentElement.parentElement.children[3];
            temp.children[0].innerHTML = video.EncodingStatus;
            temp.children[1].innerHTML = video.VideoProgress;
        }
    }, log);
    return data;
}

The above function is called with the following function call:


function getVideoForReview(call) {
    return datacontext.getVideosPage(1, vm.pageSize, vm.CurrentPage, call, '').then(function (data) {
        vm.Users = common.getVideoUsers(data);
        return vm.videos = common.populateVideoStatus(data);
    });
}

An interval function named doTimeout is invoked as follows:


function doTimeout() {
    getVideoForReview(true).then(function (data) {
        setTimeout(doTimeout, 5000);
    });
}

The intended behavior involves loading the directive and video upon page load, followed by periodic updates to the status and progress values without reinitializing the video player.

  • Loading directive and video on page load
  • Interval updates status (makes an API call) and updates DOM

Is it possible to achieve this functionality as desired?

Answer №1

Are you certain that the element being targeted with temp is correct?

From my perspective, it seems like you are assigning temp to the monster-admin-video-player div instead of the monster-admin-video-caption div.

You might want to consider trying this instead:

var temp = videoPlayer.parentElement.parentElement.children[3];

Additionally, do you think it could be feasible for the populateVideoStatus function to simply update the $scope.video.EncodingStatus and $scope.video.VideoProgress in your existing template rather than directly manipulating the DOM innerHTML?

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

Is it possible for me to transform this code into a useful helper function?

I am looking to optimize this conditional code by converting it into a helper function using a switch statement instead of multiple if statements. How can I achieve this in a separate file and then import it back into my component seamlessly? import { ...

Achieving a successful 200 response from CORS in node-http-proxy for OPTIONS requests

I'm currently working on getting a web page up and running on :9000 to send a request to a reverse proxy operating in node on :8080 so that it can accept requests as if they were from the same domain. I've discovered that because different ports ...

React date format error: RangeError - Time value is invalid

I'm utilizing a date in my React app using the following code: const messageDate = new Date(Date.parse(createdDate)) const options = { month: 'long', day: 'numeric', hour: 'numeric', minute: 'numeric' } as const ...

Concealing overflow for text content through CSS styling

I am currently working with an element that contains both an image and text. View the Fiddle here Note: To see the full grid, resize the preview accordingly. The CSS I have written is as follows: .gridster .gs-w .item{ position: relative; wi ...

The modal in Angular UI Bootstrap is returning an undefined result

Currently, I am in the process of developing an app that involves loading a modal upon clicking a button within an ng-grid row. The modal is correctly displayed with all the necessary data, but unfortunately, I am facing an issue when attempting to retriev ...

Providing data in response to a completed form submission

As a beginner, I'm attempting to accomplish the following task: a user selects options from three dropdown menus within a form, and the chosen values are then sent to another file for processing. action="process.php" method="post" In the processing ...

Tips for managing the ever-evolving language state in expressJS

I am currently working on a project utilizing nodeJs, handlebars, and the expressJs framework. I have implemented a language change functionality using the i18n-express module. This module adds a query string at the end of the URL when changing languages. ...

What is the solution for the error "Build error occurred ReferenceError: self is not defined" when building a NextJs application?

pages/components/moru-sdk.js // https://libraries.io/npm/moru-web-sdk import { MoruCheckout } from "moru-web-sdk"; function MoruService() { const options = { access_key: "test_9425294388834bdface7d1b58fd538bf67627d9408fe4f258982 ...

Once I incorporated Bootstrap into my project, I noticed a noticeable white space between the div elements

Welcome to My Code Playground I was sailing smoothly with my project until I decided to include Bootstrap. Seems like there's something missing in the details, so here I am reaching out. If you spot the issue, please feel free to correct my code. &l ...

Exploring creative solutions for generating PDFs with Node JS

Looking for a way to generate PDF Documents in Node.JS? Is there an alternative solution for organizing templates for various types of PDF creation? I've been utilizing PDFKit for creating PDF Documents on the server side with Javascript. Unfortunate ...

Utilizing the "return" keyword in Javascript outside of function declarations

Exploring the Impact of Using the Return Keyword in JavaScript Scripts Beyond Functions in Browsers and Node.js Recently, I experimented with utilizing the return keyword in a Node.js script like so: #!/usr/bin/env node return 10; My initial assumption ...

Displaying the saved MTRC (markdown-to-react-components) content from the database

I currently have data stored in a database that has been produced using the markdown-to-react-components package as MTRC(content).tree What is the best way to render this content? I've experimented with various approaches, such as dangerouslyInsertHT ...

What are the best practices for utilizing ESM only npm packages alongside traditional npm packages within a single JavaScript file?

Hey there, I'm fairly new to web development and I encountered a problem when trying to require two packages, franc and langs, in my index.js file. It turns out that franc is now an ESM only package, requiring me to import it and mention type:module i ...

JavaScript: Modifying the Style of a :lang Selector

Currently, I am working on creating a basic multilingual static website using only HTML5, CSS3, and vanilla JavaScript. The structure of the HTML looks something like this: <html> <head> <title>WEBSITE</title> ...

The image is not appearing in my small AngularJS application

I have developed a small application that converts Fahrenheit to Celsius and I am trying to display a relevant image based on the Fahrenheit temperature input. However, I am facing difficulties in getting the image to display correctly. Can someone please ...

Whenever I attempt to start my ReactJS project using the command line with `npm run it`, I keep encountering an error

Encountered an issue with the webpack-dev-server script while working on my project. Ensure that your node.js and npm versions are up to date. If they are, the problem might lie within the reactjs package rather than npm itself. Kindly inform the author ab ...

Just beginning my journey with coding and came across this error message: "Encountered Uncaught TypeError: Cannot read property 'value' of null"

As a newcomer to the world of coding, I am excited about working on a side project that allows me to practice what I am learning in my courses. My project so far is a temperature calculator that incorporates basic HTML and JS concepts. My goal is to improv ...

What is the best way to keep track of the most recent 100 items?

In Angular, I want to store the last 100 items to display. Currently, I am using an array and inserting items with 'array.push'. If this method is not effective for this scenario, what alternative approach can I take? Here is a snippet of the co ...

Differentiating Typescript will discard attributes that do not adhere to an Interface

Currently, I am working with an API controller that requires a body parameter as shown below: insertUser(@Body() user: IUser) {} The problem I'm facing is that I can submit an object that includes additional properties not specified in the IUser int ...

Utilizing a function within the App.js file located in the public folder using React JS

I need to execute a function called callMe that is defined in src/App.js from the public folder. In App.js import messaging from './firebase-init'; import './App.css'; function App () { function callMe() { console.log('Call m ...