Problem: Implementing multiple templates in a directive for simultaneous loading

I am facing a problem with loading multiple templates through a directive. In this scenario, I pass some values to the controller scope and within the directive, I check for these values to load the corresponding HTML template.

First HTML:

<a class="col-xs-3" > <div stop-watch template="topic-view" name="oCandidateDetails.name" time-of-interview="oCandidateDetails.doi" class="stop-watch"></div> </a>

Second HTML:

<div stop-watch template="candidate-view" name="candidateInfo.name" time-of-interview="candidateInfo.dateOfInterview" class="stop-watch"></div>

Directive:

angular.module('iSourcingApp.tpModule')
.directive('stopWatch', function() {debugger
    return {
        restrict: 'A',
        templateUrl: '<ng-include src="getTemplateUrl()"/>',
        replace: false,
        scope: {
            name: "=",
            timeOfInterview: "=",
            template:"="
        },
        controller: function($scope, $interval) {debugger
            $scope.getTimeRemaining = function(endtime) {
                $scope.t[$scope.name].total = Date.parse(endtime) - Date.parse(new Date());
                $scope.t[$scope.name].seconds = Math.floor(($scope.t[$scope.name].total / 1000) % 60);
                $scope.t[$scope.name].minutes = Math.floor(($scope.t[$scope.name].total / 1000 / 60) % 60);
                $scope.t[$scope.name].hours = Math.floor(($scope.t[$scope.name].total / (1000 * 60 * 60)) % 24);
                $scope.t[$scope.name].days = Math.floor($scope.t[$scope.name].total / (1000 * 60 * 60 * 24));
            }
            $scope.initializeClock = function(endtime) {
                $scope.t = {};
                $scope.t[$scope.name] = {};
                $scope.updateClock = function() {
                    $scope.getTimeRemaining(endtime);
                    $scope.t[$scope.name].hours = ('0' + $scope.t[$scope.name].hours).slice(-2);
                    $scope.t[$scope.name].minutes = ('0' + $scope.t[$scope.name].minutes).slice(-2);
                    $scope.t[$scope.name].seconds = ('0' + $scope.t[$scope.name].seconds).slice(-2);

                    if ($scope.t[$scope.name].total <= 0) {
                        clearInterval($scope.timeinterval);
                    }
                }
                $scope.updateClock();
                $scope.timeinterval = $interval($scope.updateClock, 1000);
            }
            $scope.initializeClock($scope.timeOfInterview);
            //function used on the ng-include to resolve the template
            $scope.getTemplateUrl = function() {debugger;
                //basic handling
                if ($scope.template == 'candidate-view') {
                    return './tpModule/views/stopWatchView.html';
                }
                if ($scope.template == 'topic-view') {
                    return './tpModule/views/topicStopWatchView.html';
                }
            }
        }
    };
});

The issue I am encountering is an error that states:

angular.js:13708 Error: [$compile:tpload] Failed to load template: <ng-include src="getTemplateUrl()"/> (HTTP status: 404 Not Found)

I cannot seem to figure out why this error is occurring.

Any assistance would be greatly appreciated.

Answer №1

TemplateUrl is not being used here,

template: '<ng-include src="fetchTemplateUrl()"/>',

Answer №2

It appears that the issue lies within your URL. In order to fix this error, double check that the template URL is spelled accurately and resolves to the correct absolute URL.

Here's a potential solution:

'../tpModule/views/stopWatchView.html'

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 there a way to determine if JavaScript is responsible for triggering the update on my update panel?

To ensure that the update panel with a user control in it only fires after the page has fully loaded, I have implemented the following javascript code: <script type="text/javascript"> function pageLoad(objSender, args) { Sys.WebF ...

jQuery technique for loading images

Here is the issue at hand: I am attempting to utilize jQuery to accelerate image loading on my webpage. To achieve this, I have a code snippet specifying an initial image that should be replaced with another image once the page has finished loading. < ...

After exporting static HTML, the links in Next.JS seem to become unresponsive

Exploring the world of NEXT.JS for the first time and encountering challenges with deploying a static site. In my component Nav.tsx, I have the following structure: const Nav = () => { return ( <nav className='nav p-3 border-bottom&a ...

Enhance information flow within pages using SWR in NextJS

Utilizing SWR in a NextJS project has been a great experience for me. I have successfully fetched a list of data on my index page and added a new entry to the data on my create page. Now, I am looking to take advantage of SWR's mutate feature to updat ...

How can you create an array of data objects in React by filtering them based on specific keys?

Currently, my work involves handling data structured as follows:- { 0: buyAmount: 16.664328043964396 buyAmountInUsd: 16.685266204095775 date: {date: '2021-12-07'} sellAmount: {USD: 500, INR: 35000} 1: buyAmount: 1004.7015442959262 ...

Error: Attempting to access 'rejectWithValue' property on an undefined value in Redux Toolkit

I am currently working on developing a full stack MERN application that involves implementing basic CRUD operations. I have successfully completed the backend REST API and tested all endpoints in Postman, where they are working as expected. However, on the ...

Steps to verify if a property of an object in an array aligns with any of the values in a separate object array

The header information might seem complicated at first, but let me simplify it for you. Consider the following object: const users= [ { id:"1", name:"John", email:"<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data ...

Troubleshooting CodeIgniter's AJAX call functionality issue

I have been attempting to test AJAX functionality within CodeIgniter, but unfortunately, I haven't had any success so far. Can someone please point out where I might be making a mistake? Below is my test_page.php: <!DOCTYPE html> <head> ...

Database entry issue: PHP form is not submitting via AJAX

I've been struggling to make this work for quite some time now, and I have gone through numerous responses to similar queries (How to add AJAX Submit to PHP validation and return message? , ajax submit form why it cannot echo $_POST) but unfortunately ...

Issue with integrating Razorpay into a Node.js Express application

I am currently working on setting up a checkout page using nodejs and express with Razorpay as the payment gateway. The issue arises when trying to run the checkout() function by clicking the "Checkout" button within my shopping-cart.hbs file. Despite havi ...

How can I create a script in Discord.js that automatically sends users their information upon joining the server?

I'm currently working on developing a code that automatically sends the user's avatar, username, ID, account creation date, server join date, and status when they join The structure of the code looks something like this: module.exports = (Discor ...

What are some methods to avoid clipping absolute positioned elements while maintaining a box shadow around the parent div?

Here is an example to illustrate my question: Example Code The code provided above is a simplified version of my actual code. I am facing an issue where setting the wrap-div to overflow: visible prevents the menu from being cut off, but it also causes the ...

Google form: Can you explain the process of saving form responses in an array and sending them to a cloud system via a POST request using JavaScript or Google App script?

I am currently working on a project where I need to store Google Form responses in an array instead of a Google Sheet. After collecting the responses, I plan to extract specific elements from the array and use them to create a new project through an API. A ...

What is the best way to show an empty div in this situation?

I am trying to showcase my array in my application. Here is what I have: JavaScript $scope.array1 = [' ',' ',1,2,3,4,5]; $scope.array2 = [6,7,8,9,10,' ',' ']; $scope.array3 = [12,13,14,15,16,17]; HTML <div n ...

Steps for converting a hexadecimal binary string to Uint8Array

Within this text lies a series of hexadecimal bytes: const s = "\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x8bV23J15O4\xb14\xb1H61417KKLL\xb50L5U\x8a\x05\x00\xf6&b ...

Selecting Segmented Button Options using SAPUI5

In my custom SAUI5 application, I have implemented two Segmented button items - Delivery and Collection. To differentiate between the two buttons and determine which one is clicked, I aim to pass "D" as a flag for Delivery and "C" as a flag for Collectio ...

Send multipart form data to a different server via pipe

I need assistance with handling a POST request on my Node Express server for uploading images through multipart form data. Currently, my Express app is set up to use body parser which does not support multipart bodies and suggests using alternative librari ...

What is the reason for JSX treating empty spaces as children?

Upon a recent discovery, I have come to learn that in react, empty strings can be passed as children. function App() { return ( <Comp> {} {} </Comp> ); } Directly copied from React Developer Tools, the result is as follows: { "c ...

Function that returns an Observable

In my typescript code, I have a function that looks like this: getConfigurations() { let sessionConfig = sessionStorage.getItem('config'); if(sessionConfig) return of(sessionConfig); else { this.dataService.getRoute(& ...

Operating the Heroku server deployment

I recently deployed a React app on Heroku with Express. However, I encountered an error in the console stating: "Refused to load the image 'https://sporthelper.herokuapp.com/favicon.ico' because it violates the Content Security Policy directive: ...