Struggling to integrate an Angular App within an MVC Layout

I have a website with an MVC Site that utilizes a layout. Within the layout page, I have integrated an Angular App, Models, and Controllers which are functioning correctly. However, on one of my pages displayed within the layout, I am attempting to incorporate another Angular App & Controller with basic functions. You can view the concept here: Plunker for example.

Additional information:

  • I have referenced both of the .js files in the layout head tag:

    <script src="~/Scripts/AdminVM.js"></script>
    <script src="~/Scripts/ShopVM.js"></script>
    
  • All code in my layout page utilizing the first App is enclosed between two div tags. The first div has ng-app = "FirstApp", and the second has ng-controller = "FirstController".

  • I have tried the following:

    1. Inserting the two div tags with ng-app = "SecondApp" and ng-controller = "SecondController" inside my .cshtml file where the code is located.
    2. Placing the two div tags within the body of my layout page and using @RenderBody() between them.

I am unsure of what I am doing wrong as even the simplest tasks are not working:

ShopVM.js

var app = angular.module("ShopApp", []);
app.controller("ShopViewModel", function ($scope, $http) {
    $scope.test = "Test123";
});

Shop.cshtml (Not the layout file)

<div ng-app="ShopApp">
    <div ng-controller="ShopViewModel">
        <ul class="nav nav-tabs nav-justified">
            <li role="presentation" class="active"><a href="#">Home</a></li>
            <li role="presentation"><a href="#">Cat1</a></li>
            <li role="presentation"><a href="#">Cat2</a></li>
        </ul>
        <div>{{test}}</div>

        <input id="Text1" type="text" ng-model="Shop.Test"/>

    </div>
</div>

However, when I check, all I see is a simple test: {{test}}

What could be the issue with my code?

Answer №1

I am trying to incorporate another Angular App and Controller into one of my pages that is displayed within the layout.

Unfortunately, Angular does not allow nested apps. Since you are already including the first app in the layout page, attempting to add a second one will result in it being nested within the first app.

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

Understanding how to iterate through an array of objects using ng-repeat, even when the keys are unknown

I am trying to dynamically generate the content and properties of a table cell using an array of objects. The challenge is that the keys of the objects in the array may vary, so I need a generic way to access the keys from each object. I attempted to use n ...

Activate Bootstrap modal using an anchor tag that links to a valid external URL as a fallback option

To ensure accessibility for users who may have javascript disabled, we follow a company standard of developing our web pages accordingly. Our target demographic still includes those familiar with VCRs blinking 12:00. One particular challenge involves a te ...

tips for dealing with nested json objects in C#

After sending a URL request and receiving a response in curl, I convert it into a JSON object that contains nested objects with numeric and dot values like 924.136028459. Here is an example: string arr1 = "{ "success":1, "results":[ ...

Trouble with a basic Angular demonstration

After replicating an angular example from w3schools (found here), I encountered some issues with it not functioning correctly. Despite my efforts, the code appears to be accurate. Can anyone spot what might be going wrong? To provide more context, here is ...

Perform a comparison between a specific string in the API response and extract its corresponding value

Seeking assistance with querying a REST API endpoint to filter for a specific value in the response data. Referencing the code snippet below: public async Task<RmRoom> GetRoomsDeatil() { // Code for querying the endpoint here } ...

What is the best way to properly showcase text retrieved from a database in HTML?

I am developing an application with the use of PHP and MySQL. The data in the database is stored as shown below: https://i.sstatic.net/rHj1x.png However, when the result is displayed on the HTML page, it appears like this: https://i.sstatic.net/r7VTP.p ...

How should I fix the error message "TypeError encountered while attempting to import OrbitControls"?

Encountering error while attempting to import OrbitControls JS: import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls' const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window. ...

Rows in a table will not decrease when added anew

On a page that allows adding and deleting rows from a table of input fields, the following code functions properly for existing fields. However, when attempting to add new rows and delete them in a sequential manner that requires replacing the ID and name ...

The Jquery Object #<Object> does not have the 'getElement' method available

I've been attempting to set up this table, following the instructions here: Despite verifying that my browser is correctly pulling the CSS and .js files, I keep encountering an error related to my sortabletable.js file. (screenshot of the error) htt ...

Creating custom CSS data-tooltip for image maps without the use of jquery

I stumbled upon the Pure CSS Tooltips (data-tooltip) feature showcased at http://www.frequency-decoder.com/demo/css-tooltips/, and I am eager to implement it on a specific area of an image map in a rectangular shape. However, despite finding a JavaScript c ...

Steps for dynamically expanding a textarea in Selenium WebDriver when the element path is constantly changing

I am facing a challenge with resizing a textarea that has a dynamic xpath. I am unable to use the following JavascriptExecutor commands: (JavascriptExecutor) driver.executeScript("document.getElementById('someID').setAttribute('rows', ...

The order of execution for JavaScript functions may get disrupted when using the sleep function

My goal is to hide a specific element and then display a different element after waiting for one second. Here's the simplified version of my code: function pause(milliseconds) { var start = new Date().getTime(); for (var i = 0; i < 1e7; i++ ...

Where should AJAX-related content be placed within a hyperlink?

When needing a link to contain information for an AJAX call, where is the correct place to include the info? I have typically placed it in the rel attribute, but after reviewing the documentation for rel, it appears that this may not be the right location ...

Is it advisable to utilize jQuery's parseJSON/getJSON functions?

Upon examining the jQuery parseJSON function, I discovered that it essentially performs a basic regex validation: parseJSON: function( data ) { if ( typeof data !== "string" || !data ) { return null; } // Remove leading/trailing white ...

The close button on the jQuery UI Dialog fails to appear when using a local jQuery file

I may sound silly asking this, but I have a simple webpage where I've added a jQuery modal dialog box. Strangely, when I link directly to the jQuery files online (like http://code.jquery.com/ui/1.10.3/themes/smoothness/jquery-ui.css), everything works ...

Improving the efficiency of AES decryption in Node.js

I had the idea to build a webpage that would display decrypted data fetched from the server. The app.js file on the server reads and decrypts all the data from a specific folder. var http = require('http'); var path = require('path'); ...

Issue with MVC page redirection not functioning properly after successful completion of an AJAX request

After successfully retrieving data from an AJAX call, I am trying to redirect to '/Account/Index' in the AJAX success function. However, for some reason, the redirection is not working as expected. Is there any other way to perform a redirection ...

Integrate actual credentials into S3Client using redux async thunk

My S3-like react application with redux is powered by AWS SDK v3 for JS. The client initialization in my auth.js file looks like this: auth.js export const s3Client = new S3Client({ region: 'default', credentials: { accessKeyId: 'te ...

Using angular-ui-router compatibility with Internet Explorer 8

I've been incorporating angular-ui-router into my current project and everything was running smoothly in chrome & firefox. However, when I attempted to test it in IE8, it failed to function properly. An error message stating 'TypeError: Objec ...

Why React.js and webpack are restricting the use of var, let, const?

I'm facing a puzzling issue that I just can't seem to solve. Let me show you a snippet from my Graph.js file: class Graph extends React.Component { @observable newTodoTitle = ""; s = 40 The error in webpack is showing up like this: E ...