Looking to have two separate modules on a single page in AngularJS, each with its own unique view

<!DOCTYPE html>
<html>
  <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css">
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
        <script>
          var moduleA = angular.module("MyModuleA", []);
          moduleA.controller("MyControllerA", function($scope) {
              $scope.name = "Azhar";
          });

          var moduleB = angular.module("MyModuleB", []);
          moduleB.controller("MyControllerB", function($scope) {
              $scope.name = "Khan";
          });
        </script>
    </head>
    <body>
        <div id="AgeCalc">
            <h1>Age Calculator and Currency Converter App</h1>
            <div ng-app="MyModuleA" ng-controller="MyControllerA">
                {{name}}
            </div>
        </div>

        <div id="Currency Converter">
            <h1>Currncy Converter</h1>
            <div ng-app="MyModuleB" ng-controller="MyControllerB">
                {{name}}
            </div>
        </div>
    </body>
</html>

Answer №1

       
<html>
<head>
    <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
</head>
<body>
    <div id="App1" ng-app="myApp1" ng-controller="MyControllerA">
        <h1>My Name</h1>
        <div >
            <span>{{name}}</span>
            
        </div>
    </div>

    <div id="App2" ng-app="myApp2" ng-controller="MyControllerB">
        <h1>My Surname</h1>
        <div >
            <p>{{name}}</p>
        </div>
    </div>
    <script>
            angular.module("myApp1", [])
            .controller("MyControllerA",
                function($scope) {
                    $scope.name="sagar";
                   
                }
            );
            angular.module("myApp2", [])
            .controller("MyControllerB",
                function($scope) {
                    $scope.name = "chopada";
                }
            );
            angular.bootstrap(document.getElementById("App2"),['myApp2']);
    </script>
</body>
</html>

Feel free to reach out if you need any further assistance.

Answer №2

To initialize the Angular applications manually, follow these steps. For more information, refer to this link: https://plnkr.co/edit/iW8GzBgexjylXiq1IWtp?p=preview

    <div id="AgeCalc">
        <h1>Age Calculator</h1>
        <div ng-app="MyModuleA" ng-controller="MyControllerA">
            {{name}}
        </div>
    </div>

    <div id="Currency Converter">
        <h1>Currncy Converter</h1>
        <div ng-app="MyModuleB" ng-controller="MyControllerB">
            {{name}}
        </div>
    </div>

    var moduleA = angular.module("MyModuleA", []); 
moduleA.controller("MyControllerA", function($scope) { $scope.name = "Azhar"; });

var moduleB = angular.module("MyModuleB", []);
moduleB.controller("MyControllerB", function($scope) { $scope.name = "Khan";});
 angular.element(document).ready(function() {
      angular.bootstrap(document, ['MyModuleA','MyModuleB']);
    });

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

What is the best way to find out if multiples of a specific time interval can evenly divide the time between two

I'm currently utilizing Luxon for handling dates and durations. I have two specific dates and an ISO duration, and I am looking to figure out how to determine if the interval between the dates is a multiple of the specified duration without any remain ...

Building a straightforward RESTful API for user authentication with Node.js, MongoDB, and Express.js

Can someone provide guidance on creating a RESTful API using Node.js, Express.js, and MongoDB? Specifically, I am looking for assistance with writing the schema for login and sign up pages, as well as comparing data in MongoDB using Node.js Express.js. As ...

Using sql.js to import CSV files into SQLite databases

Is it possible to import a CSV file into a SQLite database using JavaScript instead of the command line? I am currently utilizing the sql.js library to work with SQLite in Javascript. I appreciate any help or suggestions on how to accomplish this task. Th ...

Fill an HTML div with JSON data obtained from a server

I am trying to display JSON data from a json-rpc server inside an HTML div. I can see the data in Chrome and Firefox dev tools, but I need it to be displayed within a specific div on the page. I have written a script to populate the 'mybox' div, ...

Ways to verify if all files have been loaded using Firebase.util pagination

Is there a way to confirm if it is necessary to stop invoking the loadMore() function, since all documents have been retrieved from the database? In the code snippet provided, Ionic framework is used as an example, but the same concept applies to ng-infin ...

Download the latest Backand Angular SDK from npm

Currently, I have integrated the angularbknd-sdk into my Ionic 1 mobile app. I added it using Bower and then loaded it as an npm module with browserify-shym: In my package.json file "backand": "./bower_components/angularbknd-sdk/dist/backand.min.js" Aft ...

Guide on dynamically importing a module in Next.js from the current file

I am facing a challenge where I have multiple modules of styled components in a file that I need to import dynamically into another file. I recently discovered the method for importing a module, which requires the following code: const Heading = dynamic( ...

What is the best way to close all modal dialogs in AngularJS?

Back in the day, I utilized the following link for the old version of angular bootstrap: https://angular-ui.github.io/bootstrap/#/modal var myApp = angular.module('app', []).run(function($rootScope, $modalStack) { $modalStack. dismissAll( ...

What is the best method for choosing a document from a Firebase based on its creation time?

Currently delving into Firebase as part of my project, struggling with setting queries in the Database. I've provided a breakdown of my Firebase database structure below: Looking to retrieve the most recently created document from the 'subscrip ...

Incorporating a personalized image to create custom icons on the Material UI bottom navigation bar

Is it possible to replace the default icon with a custom image in material ui's BottomNavigation component? I'm curious if Material UI supports this feature. If you'd like to take a closer look, here is the link to the codesandbox. ...

Trouble with triggering HTML5 FileReader() functions

I'm having trouble determining why neither readSuccess() nor readFailure() are being executed in the code snippet below: function readMyFile(){ var reader = new FileReader(); reader.onload = readSuccess; reader.onerror = readFailure; ...

Restrict the number of rows displayed in the ui-grid to the maximum

I'm looking to adjust the height of the ui-grid so that it fits the size of 3 rows. After reviewing the ui-grid documentation, I noticed that there is a minRowsToShow property available, but couldn't find an equivalent for maxRowsToShow. I' ...

AngularJS: How Components Communicate by Interpolating Child Content

Here is an example showcasing intercomponent communication I am looking to achieve a slightly different functionality. Let's say I want the pane content to act as a tab name. For instance <my-tabs> <my-pane>Hello</my-pane> < ...

Sorting a Javascript table performs effectively, however, the results may vary when iterating through all the indexes

I'm currently using a function to sort a table I have: function ReorderSupplyGP(table){ table.find('tr:not(.kn-table_summary)').sort(function (a, b) { var tda = $(a).find('td:eq(1)').text().trim(); var tdb = $(b).find(&a ...

Which is the better option for setting a title: using .prop or .attr?

I came across a comment that mentioned The suggestion was to utilize the .prop() method instead of .attr() when setting the "title" property in jQuery versions 1.6 or newer. Could someone provide an explanation for this recommendation? ...

Sending JSON data from the primary window to the secondary window in Electron - A step-by-step guide

I am currently working with a set of 3 files. index.html: ... <a href="#" onclick="fetch(function(data) {console.log(data); subWindow(data)})">subWindow</a> ... The fetch() function retrieves a callback in JSON format. subWindows.js: let m ...

Which is better: Utilizing Ajax page echo or background Ajax/direct HTML manipulation?

I am facing a dilemma and I could really use some guidance. Currently, I am in the process of developing an ordering system using PHP/Smarty/HTML/jQuery. The main functionality revolves around allowing sellers to confirm orders on the site. My goal is to ...

How can the dependencies object be extracted from the package.json file in an Angular project?

Scenario: I am managing multiple Angular applications within the same project. Whenever I need to upgrade an npm package, I find myself having to manually update the package.json files in each application. While I attempted a mono repo approach, it did not ...

Switching perspective in express with Pug

Hello everyone, I'm still getting the hang of using Node.js with Express and Jade. I've successfully set up a basic 1 page app where a login page is displayed by default. Once the user logs in and is authenticated against a database, the function ...

Utilizing ExpressJS to refresh database query after new record insertion

I'm a beginner in using expressJS and I have a question about querying the database (mongo in this case) to retrieve all records after adding one. exports.get = function (db) { return function (req, res) { var collection = db.get('n ...