Having multiple Angular two applications running simultaneously within a single webpage

I have encountered an issue while trying to display two separate Calendars on a single page. The first Calendar loads successfully, but the second one does not load at all. There seems to be no attempt made to load it.

As I am relatively new to Angular, I am unsure if what I am attempting is appropriate in the context of a one-page application, or if there is a better way to achieve this.

I am open to any suggestions and guidance!

Calendar App Utilized: https://github.com/mattlewis92/angular-bootstrap-calendar

Front end (Trimmed down)

<div class="col-lg-9 panel panel-default" id="Calandars">
<button class="btn dropdown" data-toggle="collapse" data-target="#userCal" data-parent="#Calandars"><i class="icon-chevron-right"></i> User Calendar </button>
<button class="btn dropdown" data-toggle="collapse" data-target="#GlobalCal" data-parent="#Calandars"><i class="icon-chevron-right"></i> Global Calendar</button>
<div class="accordion-group">
<div id="userCal" class="collapse indent">

  <!---User Calendar Configuration - Working Calendar-->
  <div ng-app="UserCal" class="textfix">
    <div ng-controller="Cal as vm">
      <h2 class="text-center">{{ vm.calendarTitle }}</h2>
          ... [trimmed for brevity] ...
      </mwl-calendar>
    </div>
  </div>
</div>

<div id="GlobalCal" class="collapse indent">
  <!---Global Calendar Configuration -- Non-Working Calendar-->

    <div ng-app="UserCal" class="textfix">
      <div ng-controller="GlobalCalCon as vm">
        <h2 class="text-center">{{ vm.calendarTitle }}</h2>
            ... [trimmed for brevity] ...
        </mwl-calendar>
      </div>
    </div>       
  </div>

Javascript Behind

angular.module('UserCal', ['mwl.calendar', 'ui.bootstrap', 'ngAnimate'])
.controller('Cal', populateCal)
.controller('GlobalCalCon', populateGlobalCal);

function populateCal($http) {
  Do Stuff
  angular.copy(MyData, vm.events)
};

function populateGlobalCal($http) {
  Do Different Stuff
  angular.copy(MyData, vm.events)
};

Answer №1

Hey there, it looks like you have included the UserCal module twice in this section. Since this is your main SPA module, it should only be included once.

To resolve this issue, make sure to add ng-app="UserCal" to either the html or body tag and remove the extra

<div ng-app="UserCal" class="textfix">
from the HTML code.

Once you make this adjustment, both calendars should work as expected. Happy coding!

Answer №2

If you find yourself encountering issues, it could be due to the duplication of ng-app in your code. Remember, it is essential to declare ng-app only once, preferably at the beginning of your page or directly on the html tag in your index.html file.

For index.html:

<html ng-app="UserCal">

Alternatively,

For the current page:

<div ng-app="UserCal">

     <div ng-controller="Ctrl1">
            // content goes here
     </div>

     <div ng-controller="Ctrl1">
            // content goes here
     </div>

</div>

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

Tips for avoiding redundant AJAX requests

Currently, I am working with JavaScript and not jQuery. Imagine a scenario where I have 3 users in my database [Kim, Ted, Box] and 3 buttons structured as follows: <button class="user">Kim</button> <button class="user">Ted</button> ...

After implementing ajax, jQuery ceases to function

I have been working with multiple JavaScript files and everything is functioning perfectly (including functions that add styles to elements), but I am encountering an issue when trying to include the following script: <script src="http://ajax.googleapi ...

Combining JS Promise.all with onDOMContentLoaded to ensure all resources are

Is there a way to efficiently retrieve a json file for data while also waiting for the dom to load in order to populate a table simultaneously? The current method I am using is slow as it waits for the dom and then performs the get request. $(document).r ...

When integrating Stripe into my Next.js application, I encounter a build error

I encountered an error when building my Next.js app with Stripe integration using "yarn build". However, when running the app locally with "yarn dev", it works perfectly without any errors. I'm struggling to figure out why this discrepancy is happeni ...

Navigating horizontally with buttons in VueJS

I am searching for a way to implement horizontal scrolling using buttons in VueJS. The idea is to have a container with multiple divs arranged horizontally, and I wish to navigate through them using the buttons. If you want to see a similar solution using ...

Modify the anchor text when a malfunction occurs upon clicking

Whenever I click on the link, I am able to retrieve the correct id, but the status changes for all posts instead of just the selected item. Below is the HTML code: <div th:each="p : ${posts}"> <div id="para"> <a style="float: right;" href= ...

Click on a new tab to enable printing options for the page

I am looking to enhance the print page functionality on my website. Currently, when the print icon in the footer is clicked, it opens the printer dialog box directly. I would like to change this behavior so that when the Print icon is clicked, the contents ...

The second instance of a React Paginate on the same page remains static and does not trigger a

Having a bit of trouble with using react-paginate for pagination - I have two instances on the same page (one at the top and one at the bottom). When a new prop is received, only the top instance gets re-rendered. The code seems to be working fine as all ...

Disallow the use of punctuation marks such as dots, plus signs, minus signs, and the letter 'e' when entering

Is there a way to restrict the input of a dot, plus sign, minus sign, or letter 'e' when using semantic-ui-react library? I have searched for solutions but have not found any that work. Can someone provide assistance with this issue? ...

Type of variable that is not an array

I need a quick way to check if a value is an object {} but not an array []. The code I currently have is: function isPlainObject(input) { return !Array.isArray(input) && typeof input === 'object'; } Is there a more concise method to a ...

Tips on deactivating a button after it has been clicked once within a 24-hour period and reactivating it the following day with the use of JavaScript and Angular

Is it possible to disable my button after one click per day, and then automatically re-enable it the next day once a user has entered details using the submit button? I need assistance with JavaScript or AngularJS for this functionality. ...

prevent parent jQuery functions from interfering with child function execution

I am facing an issue with conflicting jQuery functions between parent and child elements. The child function is a bootstrap function, while the parent is a custom function. The main objective is to limit the height of the parent div (refer to the code belo ...

Issue with parse-angular-patch no longer functioning

My experience with parse-angular-patch was going great until I found out that parse.com is shutting down in a few months. To continue using the parse SDK with a parse open source server, upgrading the javascript SDK version to 1.9.2 is necessary. Attempti ...

Displaying a table in Chrome/Firefox with a mouseover feature

Hovering over the rows of this table triggers a display of descriptions. html: <tr title="{{transaction.submissionLog}}" class="mastertooltip">... JavaScript: $('.masterTooltip').hover(function(){ // Hover functionality ...

The Bootstrap modal causes the scrollbar to vanish upon closure

Despite trying numerous solutions and hacks on this issue from StackOverflow, none of them seem to work for me. Currently, I am utilizing a modal for the login process in Meteor (e.g. using Facebook login service) which triggers a callback upon successful ...

There appears to be an issue with the functionality of the Bootstrap toggle tab

Currently, I am facing a toggle issue and having trouble pinpointing the root cause as there are no errors appearing in the console. The problem involves two tabs that can be toggled between - "pay" and "method". Initially, the default tab displayed is "pa ...

Creating personalized tags or components by utilizing insertAdjacentHTML in Vue

With the use of insertAdjacentHTML, I am able to create HTML elements such as div and span, but it seems that I cannot generate custom tags like <myComponent> </myComponent>. I understand that insertAdjacentHTML can create HTML elements, but a ...

Enhance Compatibility: IE11 URL Polyfill

While creating a URL in my angular app using new URL, I have encountered an issue that it works on all browsers except IE11. To resolve this problem, I attempted to add "url-polyfill" to my "package.json" and imported 'url-polyfill' in the polyf ...

What is the reason for the viewport in three.js renderer not functioning properly on IE browser?

Try setting the viewport with different coordinates: this.renderer.setViewport(50, -50, this.width, this.height); What could be causing issues with IE browser compatibility? ...

In ReactJS, the way to submit a form using OnChange is by utilizing the

Is there a way to submit a form using Onchange without a button? I need to fire the form but can't insert routes as it's a component for multiple clients. My project is built using react hook forms. const handleChange = (e: any) => { c ...