AngularJS module dependencies configuration functions smoothly during initialization

The structure of my modules looks like this:

angular.module('mainModule',["cityModule", "countryModule"]);
angular.module('mapModule',[]);
angular.module('cityModule',["mapModule"]);
angular.module('countryModule',["mapModule"]);

The main module includes countryModule and cityModule. Both cityModule and countryModule depend on the mapModule.

I have a configuration set up in the mapModule.

angular.module("mapModule").config([function () {
      console.log("this is map config")
}]);

When I check the console, I notice that it only logs "this is map config" once. However, both cityModule and countryModule reference the mapModule. Shouldn't it log twice? Why does it only log once?

(I also observe that if I had a provider within mapModule, the console would still show the message only once.)

Answer №1

There is a correct single output.

According to information found in the document:

Modules have the ability to specify other modules as prerequisites. When one module depends on another, the required module must be loaded before the dependent module loads. This means that configuration blocks from the required modules are executed before the ones from the dependent module. The same goes for run blocks. It's important to note that each module gets loaded only once, even if multiple other modules require it.

In the scenario you provided, mapModule's configuration will initialize first, but just once.

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

When attempting to perform conditional rendering in React using a stateless functional component, I encounter an error stating "Unexpected token, expected ,"

Here is the code snippet: 'use strict' import React from 'react' import { connect } from 'react-redux' import { Panel, Col, Row, Well, Button } from 'react-bootstrap' const Cart = ({ cart }) => { const cartI ...

How to send a Django form using Django REST framework and AngularJS

Feeling a bit lost on how to handle form processing with django, django-rest-framework, angularjs, and django-angular. By using traditional Django techniques, I can generate a model form in my view and pass it over to my template. With the help of django ...

Using jQuery to move a div to a specific location on the page

Is there a way to translate the position of div x and y using Jquery that is compatible with all browsers, such as IE 7, IE8, IE9, and IE10? I have attempted the following: <div id="s1" style="-ms-transform:translate(159,430)"> hello ...

Examining an Array of Objects Based on Various Attributes

Looking to find a way to check if a similar object already exists in an array of objects. Specifically, I want to know if there is an object with the same make and model properties (Ford Focus): { make: 'Ford', model: 'Focus', co ...

What is the best way to send an email with a randomly generated HTML output using a <button>?

I am currently working on a feature where a random HTML output is sent to me via email whenever a user clicks on a button on the website page. The user receives a code when they click the button, and I want that code to be emailed to my address automatical ...

What is the best way to handle a $q.when promise in unit testing?

Currently, I am utilizing $q.when to transform promises from third-party sources, specifically those returned by PouchDB, into Angular promises. Here is the scenario: 'use strict'; angular.module('test', []) .service('pouchdb&a ...

Uploading CSV or text files in Node.js

I am looking to develop a function that can upload CSV or txt files into MongoDB using the MEAN stack. The function should work by allowing me to upload a file, then it will verify if it is in text/csv format before uploading it to MongoDB. I have attemp ...

AngularJS: Organizing Controllers Horizontally Within ngRepeat

My data consists of a table with 100 rows, each representing a complex object that is an instance of a specific type. User interactions trigger operations on these objects individually, with each row having unique operations independent of the others. $sc ...

Struggling to implement a vertical scroll bar in HTML code?

<body ng-app="myApp" ng-controller="myCtrl"> <div ng-show = "dataFromRest" ng-repeat = "x in dataFromRest.posts" > <div class="tittle" style="width: 25%;"> <a href="" ng-click="showDi ...

Quasar QDrawer module - locking closure

Is there a way to prevent the drawer from closing if the user has unfinished work in it? I want to be able to display a confirmation message, etc... I thought about using something like can-be-closed="canBeClosed", and then I discovered the dial ...

Retrieving items from an array based on their class association

My challenge involves handling a list of items obtained using the following code: var searchResultItems = $(resultContainerId + ' li'); Each item in the search results can have different classes. How can I extract all items with a specific clas ...

Combining input with a space character

I came across this code in an AngularJS filter. Can someone explain its purpose? input = input || ' '; https://docs.angularjs.org/guide/filter ...

"What is the best way to use jQuery to create a toggle effect where one button controls the state

I'm looking to improve the efficiency of my code, but I'm not sure where to start in terms of making it more concise and organized. Any suggestions on how to streamline this code and keep it neat would be greatly appreciated. $(document).ready(fu ...

Tips for integrating v-virtual-scroll with v-table?

My Vuetify table is handling a large amount of data – 300 rows with 20 columns, some of which have calculated rowspans. To improve performance, I'm considering using the v-virtual-scroll component. I came across this sample code, which doesn't ...

What is the best situation to utilize $(document).ready()?

After observing that using $(document).ready(..) seems to introduce a noticeable delay in applying JavaScript effects, I've been contemplating the best approach. I know that simply placing the effect in a <script> tag may not work if the DOM isn ...

Transform JSON data into a Google Sheet using Google Apps Script

Having trouble inserting the JSON response into Google Sheet using Google Apps Script with the code below. Running into errors, even though I can't seem to pinpoint the issue. Take a look at the screenshot and code snippet provided: function myF ...

How to address hover problems in D3.js when dealing with Path elements and updating tooltip information after brushing the focus

Seeking assistance with a Multi Series, Focus + Context D3 chart and hoping to address my main queries all at once. The questions that need resolving are: How can I prevent the tooltips I've generated from being affected by the hair-line (which t ...

Ensure that the div remains fixed at the bottom even when multiple items are added

Following up on the previous question posted here: Sorting divs alphabetically in its own parent (due to many lists) I have successfully sorted the lists alphabetically, but now I need to ensure that a specific div with a green background (class: last) al ...

Guide on transferring three js variable to an HTML label element

For my project, I am looking to pass three js values to the label of a div. The desired output is: stWay: stProposer: stTime: hello John 2017-09-07 I have successfully programmed a button to make div1 a ...

Vue.js - computed property not rendering in repeated list

It seems like the issue lies in the timing rather than being related to asynchronous operations. I'm currently iterating through an object and displaying a list of items. One of the values requires calculation using a method. While the direct values ...