Error Handling in Angular2 MVC 4 Project Route Issues

Here is the structure of my Mvc 4 Project with angular 2 implemented:

   Solution 'Angular2Starter'
|-- angular2Starter
|   `-- Controllers
|       `-- HomeController.cs
|-- src
|   |-- app
|   |   |-- home
|   |   |   |-- home.component.ts
|   |   |   |-- home.css
|   |   |   |-- home.html
|   |   |-- app.component.spec.ts
|   |   |-- app.component.ts
|   |   |-- app.html
|   |   |-- app.routes.ts
|   |   `-- main.ts
|   |-- systemjs.conf.js
|   `-- tmp
|-- tasks
|-- gulp.config.js
|-- gulpfile.js
|-- package.json
|-- tsconfig.json
|-- tslint.json
|-- typings.json
|-- Web.config
`-- Views
    `-- Shared
        `-- _Layout.cshtml

This is how my Layout.cshtml looks like:

<html>
  <head>
    <title>Angular 2 QuickStart</title>
    <base href="/">
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <!-- build:css assets/bundle.css -->
    <link rel="stylesheet" href="~/node_modules/font-awesome/css/font-awesome.css">
    <!-- app:css -->
    <link rel="stylesheet" href="~/src/assets/styles/main.css">
    <!-- endinject -->
    <!-- endbuild -->
  </head>
  <body>@RenderBody()
    <as-main-app>
      <i class="center-fix main-spinner fa fa-spin fa-spinner"></i>
    </as-main-app>

    <!-- build:js assets/lib.js -->
    <script src="~/node_modules/jquery/dist/jquery.js"></script>
    <script src="~/node_modules/bootstrap-sass/assets/javascripts/bootstrap.js"></script>

    <!-- 1. Load libraries -->
    <script src="~/node_modules/zone.js/dist/zone.js"></script>
    <script src="~/node_modules/reflect-metadata/Reflect.js"></script>

    <!-- Polyfill(s) for older browsers -->
    <script src="~/node_modules/es6-shim/es6-shim.min.js"></script>
    <!-- endbuild -->

    <!-- build:js assets/app.js -->
    <script src="~/src/tmp/app/bundle.js"></script>
    <!-- endbuild -->

    <!-- build:remove -->
    <script src="~/node_modules/systemjs/dist/system.js"></script>
    <script src="~/src/systemjs.conf.js"></script>
    <script>
      System.import('app/main.js')
        .catch(function(err) { console.error(err); });
    </script>
    <!-- endbuild -->
  </body>
</html>

After successfully running gulp and opening the project's index page, I encountered the following error in the console:

GET http://localhost:52994/app/app.html 404 (Not Found)
EXCEPTION: Failed to load app/app.html

I may have structured everything incorrectly, as I couldn't find any examples similar to my situation. Can anyone provide some assistance on what might be causing this issue?

Answer №1

Give it a shot

Try using System.import('app') .then(null, console.error.bind(console));

as an alternative to

Consider System.import('app/main.js') .catch(function(err) { console.error(err); });

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

Provider Template Fails to Trigger $Scope Logic

I'm working with angular ui-router and I want to display a different template for a specific state depending on a variable in the main body scope. However, when I include this conditional using $scope.data, nothing happens. The console.log() doesn&apo ...

`The utilization of a collective interface/data type within an Angular application`

I created a HeaderComponent that requires an object with the structure of {title: string, short_desc: string} as its input property. @Component({ selector: 'header', templateUrl: './header.component.html', styleUrls: ['./hea ...

The observable HTTP map appears to be more of a representation rather than a concrete entity

I seem to be struggling with understanding Typescript I expected the returned observable to have a method getTitle(), but it seems to be missing. Instead, I am getting an object that resembles AttachableContentModel without that particular method. What is ...

Can callback argument types be contingent on certain conditions? For example, could argument 0 be null if argument 1 is a string?

I am attempting to implement conditional type logic for the parameter types of a callback function. In this scenario, the first argument represents the value while the second argument could be an error message. type CallbackWithoutError = (value: string, ...

Exploring the world of third-party widgets: Comparing Angular, jQuery, and traditional JavaScript

I have a plan to develop a simple embeddable widget similar to Google ads or Facebook like box. Users will be able to easily add the widget to their website and I will extract some parameters to fetch data from my servers. Previously, I relied on jQuery f ...

Ways to retrieve data from an Observable and save it in an Array categorized by a specific identifier

The data I have is structured as follows: Location: lat: 43.252967 lng: 5.379856 __proto__: Object customerId: "5cd430c65304a21b9464a21a" id: "5d5a99c62a245117794f1276" siteId: "5d0ce7c4a06b07213a87a758" __proto__: Object 1: Location: {lat: 43.249466, lng ...

The element within the iterator is lacking a "key" prop, as indicated by the linter error message in a React component

Encountering an error stating Missing "key" prop for element in iteratoreslintreact/jsx-key {[...Array(10)].map((_) => ( <Skeleton variant="rectangular" sx={{ my: 4, mx: 1 }} /> ))} An attempt to resolve this issue was made ...

How to Retrieve JSON Object Using Dynamically Generated String in Angular

Creating a controller in Angular involves retrieving URL parts and parameters using $statePrams. The $http service is then called to retrieve data from a JSON file. Once the data is received, the content of a specific object element - determined by $state ...

When clicking to open the md-select on Angular Material 1.1.0, an unwanted [object object] is being appended

Every time I try to open the md-select input, an [object Object] (string) is added to the body tag. Click here to see the md-select input After clicking the md-select once, this is how the body looks ...

"Refreshing UI-View with AngularJS and UI-Router: A Guide on Reloading Your

I am struggling with Angular UI-Router as I am encountering an issue where the state is not being reloaded. Here is a snippet of my code: app.config(function ($urlRouterProvider, $stateProvider) { $urlRouterProvider.otherwise("/home"); $stateProvi ...

Issue with MIME handling while utilizing Vue-Router in combination with Express

Struggling to access a specific route in Express, I keep encountering an error in my browser. Additionally, when the Vue application is built, only the Home page and the 404 page seem to work properly, while the rest display a default empty HTML layout. F ...

Raycaster in Three.js fails to recognize clicks on objects

Having trouble detecting clicks on Three.js objects using a raycaster in Angular? Here's the code I'm working with: @Component({ selector: 'app-viewer-3d', templateUrl: './viewer3d.component.html', styleUrls: ['./vi ...

Having trouble accessing child directives in Angular 2 using @ContentChildren

I'm facing an issue getting nested directives from a parent directive, as @ContentChildren is not being populated. The main goal is to implement lazy-loading for images, where each image is a nested directive within the parent directive. For instan ...

Incorporating the dot notation, unleash the potential of AngularJS interpolation binding, expressed as `

I want to incorporate the AngularJS interpolation binding with dot notation. <div ng-repeat="item in items"> <input type="checkbox" ng-model="form.city.{{item.region}}.enabled"> </div> However, I keep encountering errors with the ng-m ...

Method for implementing mock values with observables in Angular

I have successfully implemented the following code to call an API. However, I now want to return a true value instead of calling the API. Strangely, when I try to return true, an error is thrown. export interface EmployeeStatus{ hasActive: boolean; } ...

Utilize Angular 9 with an M1 Mac device

Struggling to get my project, which utilizes Node 12 and Angular 9, up and running on my new M1 Mac. I used nvm to install node and the latest npm version, then ran the command npm i -g @angular/cli@9 to install angular. Even though which ng confirms that ...

Tips for obtaining a JSON response from a RESTful API in AngularJS by utilizing the $resource service

I have been working on my AngularJS code, and although I am receiving a response in the console, I am having trouble storing it in an array or JSON format. angular.module('user', ['ngResource']). config(function($httpProvider){ $h ...

What is the reason behind decorators needing to utilize apply(this) on a function?

I've been delving into the realm of JavaScript and exploring decorator code. One thing I've noticed is that when looking at decorator code like the example below, the input function always applies to 'this' even though it doesn't a ...

Share a model between two partial views within the same view

I'm facing an issue with loading two partial views in my main view. The main view is set to automatically refresh partial view 1, while partial view 2 should only update when a user clicks on an Ajax.ActionLink from partial view 1. This click event sh ...

Error in D3: stream_layers function is not defined

Utilizing nvd3.js to construct a basic stacked bar chart as detailed here I inserted the code provided in the link into an Angular directive like this: app.directive('stackBar', function() { return { restrict: 'A', ...