Multiple instances of the identical 'Angular application' displayed simultaneously on the webpage

We've created a unique Angular 1.0 application that we aim to embed as a 'widget' within another website built with classic asp.net.

During the development phase of our angular app, we take advantage of a range of gulp tools for tasks such as running karma tests, live-reload, and css compilation.

When it comes to deploying the app, our plan is to execute the 'build-app-prod' command specified in our gulpfile.js. Once the files are compiled (app.min.js, app.vendor.js, and app.min.css), we intend to copy them to a designated folder where they can be accessed. The app will then be attached, with slight configuration variations, to different dom elements. These elements will be displayed one by one in a modal popup when users click on the corresponding 'edit this' button (the angular app serves as the editing interface).

What would be the best approach to achieve this? Should we incorporate these files into the asp.net app and link the angular app using the following code snippet:

<script src="build-app-prod-folder/app.min.js" />
<script src="build-app-prod-folder/app.vendor.js" />
<link rel="stylesheet" href="build-app-prod-folder/app.min.css">

<!-- .. -->
<div id="firstAngularAppGoeshere" 
ng-app="AngularEditApp" data-param="config1Value" />

<!-- .. -->

<div id="secondAngularAppGoeshere" 
ng-app="AngularEditApp" data-param="config2Value" />

Is this the correct route to take or should we consider an alternative method?

For example, could we implement an 'angular loader' that simplifies the process by allowing us to include just one JavaScript file which then handles all the necessary dependencies and file references automatically?

Answer №1

The Angular specifications only allow for one ng-app per application. However, your desired outcome can still be achieved by utilizing an ngModule. For further information on this topic, check out the following blog post:

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

Unable to bind click eventListener to dynamic HTML in Angular 12 module

I am facing an issue with click binding on dynamic HTML. I attempted using the setTimeout function, but the click event is not binding to the button. Additionally, I tried using template reference on the button and obtaining the value with @ViewChildren, h ...

The issue of jQuery, Ajax, and MVC6 parameters becoming null after an Ajax request has been identified

Hello everyone, I am a beginner in asp.net core, c# and MVC 6. Currently, I am facing an issue with sending data over ajax to my controller. function sendAjaxData() { $.ajax({ url: "AjaxWithData", // using hardcoded value for testing purpose type ...

MTG database table issue - the add_meta_data function is not working correctly

There have been some omissions in the code for clarity. Essentially, this script retrieves a list of Magic: The Gathering cards from an XML file and populates them into a MySQL table. Subsequently, it creates a corresponding post for each card and fills it ...

Showing the value of a JavaScript variable within an HTML input field

Here is an interesting HTML structure that includes a list and input field: <li> <span>19</span> </li> <li> <span>20</span> </li> ...

Prevent certain dates from being selected in a designated input field

I am facing an issue with disabling certain array dates for a specific input field in a datepicker calendar. Even though I have included the script to exclude those dates, they are not getting disabled for that particular input field. html <input cla ...

How do you verify an OpenID Connect access token produced by Azure AD v2 in an ASP.NET Core web API?

What is the best way to verify an OpenID Connect Access Token generated by Azure AD (v2) in ASP.NET Core Web API? Here's the situation: I have an Angular 8 Client Application that receives an OpenID Connect access Token post Login. The Client can us ...

Ensuring a dependable detection of WebSocket connection status

I've been researching how to create a dependable method for recovering a WebSocket connection. After exploring various options, I discovered that one approach involves sending heartbeats (ping/pong) to the server and monitoring if the entire pong is ...

Encountering an issue with the default task in gulp, an error is displayed in Gitbash stating: "Task must have a name that is a string

Upon running the command 'gulp' in gitbash, an error is being displayed for the last line of the code, stating: throw new Error('Task requires a name that is a string'); Error: Task requires a name that is a string "use strict"; var g ...

Create a unique Bitcoin address using a derivation scheme

Starting with a derivation scheme that begins with tpub... for the testnet, I am looking to generate bitcoin addresses from this scheme. I also need a method that will work for the mainnet. Is there a library available that can assist me with this task? ...

The i18n feature in Nuxt 3 retrieves language locales from an external API

While working on my Nuxt 3 app, I encountered an issue when trying to integrate i18n. Despite conducting extensive research, I couldn't find any helpful information, hence I have a question. I am utilizing i18n with Prismic CMS. The locales array is s ...

The appearance of responsive CSS is altered when deployed compared to when it is viewed on the

I'm a beginner in web development and facing an issue with my mobile CSS. The strange thing is that when I view it on localhost, everything looks great, but once deployed (tried both Heroku and GitHub), it appears distorted. Even when I make extreme c ...

Recursive instruction malfunctioning

I'm currently trying to develop a custom recursion directive, but unfortunately it's not functioning as expected. I have followed the instructions outlined here: Recursion in Angular directives For reference, you can view the fiddle here: http ...

Preserving the original "this" context while binding a callback for a React child

class Parent extends React.Component { constructor(props) { super(props) this.handleChildOnClick = this.handleChildOnClick.bind(this) } handleChildOnClick() { /* Here, I want to perform an action that involves both Child and Parent. ...

Storing an array of objects in Firestore using JavaScript presents a challenge

I am attempting to save an object to Firestore which includes an array: { returnMode: false, id: "SE-74c5219a-acfe-4185-9e33-f78b10ac3f1e", prices: [ { price: { twoHours: 0, firstHour: 0, id: "zero&quo ...

Internet Explorer causing issues with Jasmine mocking ajax calls

Recently, I attempted to develop a spec that enables mocking out Ajax calls. The testing procedure functions seamlessly on browsers such as Chrome and Firefox; however, I encountered some difficulties while executing the test case on Internet Explorer (spe ...

Difficulty encountered when displaying JavaScript variable content within HTML in a React component

I'm currently exploring a backend administrative dashboard framework known as admin bro. My current project involves creating a tooltip component, and here is the code I have developed so far. class Textbox extends React.PureComponent { render() { ...

State is causing a conflict by allowing multiple menus to open when mapping over Menu objects

I am currently encountering an issue with my Material UI <Menu>. The problem arises when I attempt to display some data and interface functionality by mapping over a <Card>, along with adding an <IconButton> on each card that opens a menu ...

Learn how to leverage the drag and drop directive in AngularJS for your web

I integrated drag and drop functionality into my project using: https://github.com/marceljuenemann/angular-drag-and-drop-lists This is how I implemented it: <div ng-repeat="list in lists"> <div style="float: left; margin-left: 5px;"> ...

utilize ajax success method to extract json data

I'm currently working on displaying and parsing JSON data in the success function of an AJAX call. This is what I have so far: AJAX: data = "Title=" + $("#Title").val() + "&geography=" + $("#geography").val(); alert(data); url= "/portal/getRe ...

When the browser's back button is clicked, no action occurs with Next/router

I am confused about why my page does not reload when I use the browser's back button. On my website, I have a catalog component located inside /pages/index.js as the home page. There is also a dynamic route that allows users to navigate to specific p ...