Having trouble resolving the templateUrl for AngularJS in a shared module

It's really frustrating me. I have an angular module that is injected into different apps. Whenever I attempt to use templateUrl with a relative path in the shared module, it throws a 404 error.

angular.min.js:99 GET http://localhost:8001/modals/modal.html/ 404 (Not Found)

This is how my directories are structured:

order-request
  |- modals
     |- modal.html
  |- index.js
  |- InitiateTransaction.js

index.js

import * as angular from 'angular';
import InitiateTransaction from './InitiateTransaction';

export default angular
  .module('orders', [])
  .component('initiateTransaction', InitiateTransaction);

InitiateTransaction.js

export default {
  template: `<div>
    <div class="btn-group">
      <div uib-dropdown is-open="status.isopen">
        <button id="single-button" type="button" class="btn btn-flat btn-primary" uib-dropdown-toggle ng-disabled="disabled">
          Initiate Transaction <span class="caret"></span>
        </button>
        <ul class="uib-dropdown-menu dropdown-menu text-left" role="menu" aria-labelledby="single-button">
          <li role="menuitem"><a class="clickable" ng-click="$ctrl.open('subscription')">Subscription</a></li>
          <li role="menuitem"><a class="clickable" ng-click="$ctrl.open('redemption')">Redemption</a></li>
        </ul>
      </div>
    </div>
  </div>`,
  controller: class InitiateTransaction {
    constructor($scope, $uibModal) {
      this.$scope = $scope;
      this.$uibModal = $uibModal;
      this.modalInstance = null;
    }

    open(transactionType) {
      this.modalInstance = this.$uibModal.open({
        templateUrl: modals/modal.html',
        size: 'lg',
        scope: this.$scope
      });
    }
  }
};

I am not using webpack and have not been able to import html files at the top of InitiateTransaction.js

I've always believed templateUrl searches from the level of the index file for the module? Is this correct?

Is there something I should do in the app that injects this?

import '<some-working-path>/order-requests/index';

const app = angular.module('PortfolioApp', ['orders']);

Answer №1

The reason for the issue was related to how bundling was done. It was necessary to include the templates directory in the gulpfile.js file.

For example:

moduleConfig.init(require('gulp'), require('./package.json'), {
    templates: [
        moduleConfig.configDirs.sourceDir + '/modules/order-request/modals/**/*.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

Iterating through every image displayed on a webpage

Two inquiries: What is the best way to efficiently loop through every image on a specific webpage and open each one in a new browser tab? Similar concept, but instead of opening in a new tab, I am interested in substituting different images for the ...

Getting map data from Mapbox and displaying it on an HTML page

I have been working with Mapbox GL JS and successfully retrieved data in the console. However, I am facing issues when trying to display this data on an HTML page. Can anyone assist me with this problem? I specifically need the data inside mapdata to be sh ...

Parsing JSON multiple times to extract data on the top 10 games from Twitch's API

Hey there! I have a little coding challenge for you. The current code below is only fetching the first channel from the JSON. My goal is to fetch all the streams and display them in a grid format with three streams per row. Can you help me achieve this? (B ...

How do I retrieve URL parameters in Vue.js?

Hello, I am currently working on creating my own websites and I am new to vue.js. I am having trouble getting parameters from the URL. I have tried multiple methods but none seem to work. Here is an example URL: example.com:8080/login. On this page, there ...

Manipulate HTML elements using JavaScript when a key is being held down

I'm currently developing a simple game using vueJS for the frontend. I have successfully created all the necessary objects and now my goal is to enable their movement when a key is pressed. However, I am facing an issue where the object only moves on ...

Setting up parameters and arguments in Vuex mutations: A guide

I am currently developing a todo list application using Vue.js, Vuex, and Firebase. The functionality of the app seems to be in working order with the Store file effectively managing the retrieval and display of entered todo items to and from Firestore. Ho ...

Transferring data from JavaScript to PHP using the $.ajax method for storing information in a MySQL database

I am attempting to make a POST call from a JavaScript file to a PHP file in order to insert a variable into a MySQL database. Here are the basic files I am working with: 1° PHP file for sending the call <html> <head> <script ...

Unable to utilize ng-Bootstrap datepicker

I recently cloned the quickstart project from the tour of heroes guide on Angular's official website, and I wanted to incorporate the ng-Bootstrap datepicker. However, I encountered some issues with its functionality. Below are the key components of m ...

Issue with $http.get in fetching information from PHP server

Dealing with duplicate keys error in AngularJS, PHP, and MySQL I have been working on a web-based system and encountered an issue with ng-repeat displaying duplicate keys. I am unsure how to resolve this issue. The select all brand functionality seems to ...

What is the best way to transfer an id from one const to another in JavaScript?

I have 2 APIs that I am using to fetch data. The first API, called getDetails, is used to retrieve student details. Within these student details, there is an ID that needs to be fetched from the second API and displayed in the first API. The second API is ...

The redirection from Azure AD SSO is not working properly following a logout

In my quest to integrate Azure AD login into a single-page application built with ReactJS, I utilized the MSAL React package. While successfully implementing the login functionality, I encountered an issue during logout where I found myself unable to redir ...

Issue with active class in Bootstrap navigation tabs

Check out the following HTML snippet: <div class="process"> <h2 style="text-transform: uppercase;">The Application Process</h2> <br><br> <div class="row"> <div class="col-md-3" align="left"& ...

Is it possible to implement a Promise.some() function that includes a timeout

Scenario - collect multiple URLs and cache the responses. URLs that are processed quickly (e.g. within 500ms) are included in the current pass, while those that take longer are still cached for use in the next round (approximately 10 minutes later in our a ...

Creating a Controlled accordion in Material-UI that mimics the functionality of a Basic accordion

I'm a Junior developer seeking assistance with my first question on this platform. Currently, I am working with a Controlled accordion in React and need the icon to change dynamically while staying open even after expanding another panel. The logic ...

Implementing Pagination or Infinite Scroll to Instagram Feed

Currently, I am working on creating an Instagram feed for a fashion campaign where users can hashtag their photos with a specific tag. Using the Instagram API, the script will pull all recent posts with this common tag to display on the webpage. Instagram ...

What is the best location to place AngularJS scope $watch functions?

I am currently facing an issue where I need changes in an AngularJS scope to trigger actions in a model. To achieve this, I utilize the $scope.$watch() method in my item controller and integrate those controllers into directives. The issue arises when an i ...

Modifying icon color upon button click in Vue 3: A quick guide

I'm currently implementing Vue 3 into my project. Within the database, there are a total of 10 individuals, each of which should have their own card displayed. Users have the ability to add any person to their list of favorites. Below is the code snip ...

Is it advisable to incorporate both Jquery and AngularJs into progressive web applications?

Currently, I am in the process of constructing a progressive test application. So far, all the tutorials I have come across utilize native JavaScript. My inquiry is whether it is possible to leverage Jquery for streamlined code writing and implement an MVC ...

Configuring routers for my node.js application

I've been facing several challenges with setting up the routes for my node.js application. Below is a snippet of my app.js file where I call the route. const express = require("express"); const bodyParser = require("body-parser"); const app = exp ...

Using Twig in combination with Ajax to send requests using the Get method

Trying to utilize the Get method to send an Ajax request, I have encountered an issue. Despite adding an alert to my request function to confirm the link, no alert is displayed! Here is my code: Below is my html.twig view: <a href="#" onclick="reques ...