Problem with navigating in AngularJs

I am encountering an issue with angularjs routing. My objective is to append different views based on the path. I aim to achieve this by using separate ng-apps within a single HTML document like so:

<body>
    <div ng-app="header" id='header'>
        <div ng-view></div>
    </div>
    <div ng-app="content" id='content'>
        <div ng-view></div>
    </div>
</body>

Below is the app.js code snippet:

angular.module('content', []).
  config(['$routeProvider', function($routeProvider) {
    debugger;
  $routeProvider 
  .when('/101DEV/createProfile/', {templateUrl: '/101DEV/views/new-profile.html'})
  .otherwise({templateUrl: '/101DEV/views/page-not-found.html'})
}]);


angular.module('header', []).
  config(['$routeProvider', function($routeProvider) {
  $routeProvider.otherwise({templateUrl: '/101DEV/views/top-menu.html'})
}]);


angular.bootstrap(document.getElementById('header'), ['header']);
angular.bootstrap(document.getElementById('content'), ['content']);

The header section gets appended correctly, but there seems to be an issue with appending the content part even though the path matches what I expect. I am finding it challenging to identify where exactly the problem lies.

Answer №1

It is important to note that according to the AngularJS documentation, only one ng-app should be used in the HTML (Refer to http://docs.angularjs.org/api/ng.directive:ngApp). To adhere to this guideline, simply remove the ng-app directives from the HTML and implement manual bootstrapping as shown below:

<body>
    <div id='header'>
        <div ng-view></div>
    </div>
    <div id='content'>
        <div ng-view></div>
    </div>
</body>

For a visual representation of this concept, you can view an example on http://jsfiddle.net/SqK4d/

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

Is there a way to make a `select` in AngularJS refresh itself automatically?

I'm encountering an issue with the 'select' element. When I choose an option in the first 'select', the result does not immediately appear in the second 'select'. Instead, I have to manually refresh the page using 'F ...

Discovering the indices of undefined array elements in JavaScript without using a loop

Is there a way in JavaScript to retrieve the indexes of undefined array elements without using a loop? Possibly utilizing a combination of map, filter, and indexOf? I have a loop solution that I'm seeking an alternative for - something more concise, ...

Accessing QML Functions from JavaScript

Currently, I am faced with a challenge in my app development using Qt. I need to trigger a QML function from JavaScript when a specific event is triggered from my HTML page. I attempted the following method: app.html <html> <head><title& ...

Dividing the text by its position value and adding it to a fresh object

I needed to divide the paragraph into sections based on its entityRanges. Here is what the original paragraph looks like: { type: 'paragraph', depth: 1, text: 'Do you have questions or comments and do you wish to contact ABC? P ...

How to retrieve the third party child component within a Vue parent component

Within my example-component, I have integrated a third-party media upload child component called media-uploader: <example-component> <form :action= "something"> // Other input types <media-upload :ref="'cover_up ...

"Utilizing AJAX for real-time search to target the final

Recently, I've been playing around with the AJAX Live Search feature that can be found on this site: http://www.w3schools.com/php/php_ajax_livesearch.asp The way it transfers the input value via AJAX to a php file for comparison is quite interesting ...

Issue: Attempting to send a POST request to the specified API endpoint for creating a product category resulted in a 500 Internal Server Error

My current task involves inserting data into a table using the POST method with an Angular service function. angular.module("productCategoryModule") .factory("productCategoryService",productCategoryService); productCategoryService.$inject = ['$http& ...

Searching for a specific field within an array in a nested subdocument in MongoDB: What you need to know

I am having trouble retrieving lookup data for an embedded array within a document. Below is a snippet of the data: { "_id": "58a4fa0e24180825b05e14e9", "fullname": "Test User", "username": "testuser" "teamInfo": { "chal ...

The placeholder text in the matInput field is not being displayed

As a newcomer to Angular, I am facing a challenge that has left me unable to find a solution. Below is the code snippet in question: <mat-form-field> <input matInput placeholder="ZIP" style="color:red;"> </mat-form-field& ...

transition from jQuery to Zepto

I have been utilizing multiple jQuery plugins in my codebase... Recently, I decided to switch over to Zepto, but encountered an issue Uncaught TypeError: Object function (a,b){return A.init(a,b)} has no method 'data' when checking the console ...

Requesting Access-Control-Request-Headers using jQuery Ajax POST method

I am attempting to send an AJAX request to my server. Initially, I referenced a library (in the web) within a <script> tag in my HTML document and executed it using the following code: $.ajax({ url: api_url + "movie/create", type : "POST", con ...

Is there a way to instantiate a new object within the same for loop without replacing the ones created in previous iterations?

My current issue with this exercise is that as I convert the first nested array into an object, the iteration continues to the next nested array and ends up overwriting the object I just created. I'm wondering how I can instruct my code to stop itera ...

Managing various perspectives with asynchronous JavaScript and XML requests

I am currently utilizing AJAX requests (specifically, jQuery's load method) to dynamically load various views into the same HTML DIV element. While this process works smoothly, I have encountered an issue with some of these loaded pages containing ev ...

Having npm start is causing an error to be displayed

I am encountering an issue when I try to start 'npm' on my mean.js application. The error message is related to a missing file called '.csslintrc'. Below, I have included the terminal output as well as the snippet of code where the erro ...

Guide to setting up a default route that precedes all other routes in Express.js routing

I'm struggling to articulate this question correctly, so please be patient with me. Currently, I have a few routes set up: localhost:3000/index localhost:3000/home localhost:3000/login localhost:3000/forgot However, I would like to add a client n ...

Ways to retrieve a variable from outside of a function

I am in need of sending the following batch data to the database, but I am facing difficulties in including the course_id along with the batchData. Currently, I am retrieving the course_id from another service that fetches data from a course table. I am ...

Utilize jQuery to substitute numbers with strings through replacement

My question pertains to the topic discussed here. I am looking for a more refined jQuery replacement function that can substitute a number with a string. My PHP script returns numbers in the format of 1.27 Based on a specified range, these numbers need ...

Is there a way to display an alert message when a button is clicked and perform

I want to create a form that functions like this: input + input = output This form will include two input fields for numbers with a plus + symbol between them. Additionally, there will be a Calculate button that, when clicked, will display a pop-up alert ...

Utilize CDN-sourced library within an Angular component

I've been attempting to connect with the HelpScout beacon using their API methods but am struggling to access the DOM from the controller. I have experimented with functions like document.HS.beacon.ready(function() { // Open the Beacon as soon as ...

Exploring the wonders of accessing POST request body in an Express server using TypeScript and Webpack

I am currently working on a Node and Express web server setup that utilizes Webpack, along with babel-loader and ts-loader. Let's take a look at some key portions of the code: webpack-config.js: const path = require("path"); const nodeExte ...