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

Strange response received from $http GET request on Android device running Crosswalk

I am attempting to retrieve data in JSON format from an API using AngularJS. The process is successful on iOS and desktop browsers, but I'm encountering a strange response when trying it on my Android device. The request code looks like this: $http({ ...

Is it possible to use Angular CLI 6 to run ng serve with Angular 4?

I have a project using Angular 4. I recently updated my Angular CLI version: Angular CLI: 6.1.5 Node: 10.9.0 OS: win32 x64 Now I'm wondering how to run ng serve for my Angular 4 project? However, I noticed that the file angular.json is missing in ...

I'm having trouble with my AngularJS Spinner directive

Check out this simple directive I created to display a spinner on my button while something is happening remotely: http://plnkr.co/edit/rAJ4X7A3iidmqUD2M63A?p=preview Here's the html: <!DOCTYPE html> <html ng-app="app"> <head> ...

Guide on disabling withCredentials in an angularjs and expressjs project

$scope.checkStatus = function() { $http({url:'url', method:"GET", withCredentials: false, headers:{ 'Authorization': 'Token ' + token, } }) .success(function(result) { console.log("Data ret ...

When transmitting data from NodeJS, BackBlaze images may become corrupted

I have been facing a challenge in my React Native app where I am attempting to capture an image and then post it to my NodeJS server. From there, I aim to upload the image to BackBlaze after converting it into a Buffer. However, every time I successfully u ...

AngularJS: Exploring the Purpose of the '?=' Symbol in Angular Directive Scopes

Recently, I noticed some developers using '=?' within the angular scope of a directive. Could someone kindly elaborate on its purpose and how it is used? ...

What is the process for extracting components from a JSON file using an observable in Angular?

Take a look at this snippet of code: response: any; fetchData(url: any) { this.response = this.http.get(url); } ngOnInit(): void { fetchData("url.com/data.json"); console.log(this.response) } When I check the console, I see Obser ...

Having trouble retrieving the value of the hidden field using ng-model

Hello, I'm currently learning AngularJS and facing some challenges with accessing hidden field values using ng-model. Specifically, I am working on an editing modal where I need to retrieve the ID for each record. Below is my controller code snippet: ...

Restricted footage accessible through RESTful API

Hey there! I'm currently working on implementing authentication protected audio/video streaming in an Angular app using REST API. The main objective is to ensure that the audio/video content is secure and not accessible to users who are not logged in. ...

Upon upgrading @types/angular, I encountered error TS2694 stating that the namespace 'angular' does not have an exported member 'xxx'

Following the upgrade of angular and @types/angular to version 1.6.x, an array of TS2694 errors suddenly appeared: error TS2694: Namespace 'angular' does not include an exported member named 'material' error TS2694: Namespace 'ang ...

Is it possible to utilize a FOR loop in TypeScript to store an array in a variable?

Hey there pals! I could really use your brain power for a solution that requires some context. Our array ress is limited to items that meet a certain condition. After filtering the array, I need to store the new results in a different variable. I' ...

Adding a custom type to a selected option for the onChange event in React-Select can be done by modifying the

After creating a SelectBox component using react-select and applying onChange event to it, I encountered an issue. I wanted to include a type "SelectedItemType" to the selected option in the onChange event, but the property of onChange was defined as (prop ...

Issue with AngularJS directive failing to trigger on click event

I have adapted the JQuery code from my client app design into an AngularJS directive as shown below, but unfortunately the on-click event is not working properly (no action when clicking on the boxes). Could someone please help me identify what I am doing ...

How can I make a button change color dynamically in Angular when using Ionic?

<ion-col col-3> <button ion-button (click)="onPunchPress($event)"><span>1</span></button> </ion-col> <ion-col col-3> <button ion-button (click)="onPunchPre ...

Protractor's utilization of output plugins

The newest version of Protractor, 2.0.0, has introduced an interesting concept of enhancing Protractor with plugins. These plugins include built-in options such as ngHint, console, and timeline. Right now, I am in the process of getting the timeline plugi ...

Running NG BUILD from Gulp can be done using either child-process.spawn or by disabling all output in child-process.exec

Have you come across a similar question like this Call "ng build" from inside a gulp task? I have found a way to successfully build Angular using Gulp in order to prevent overflowing the output buffer. Here's how I achieved it: const child ...

Unable to pass parameters through the URL in Angular's POST request

Hey there! I'm currently facing an issue with passing a parameter in the POST method URL within an Angular service to construct a URL for fetching data from an API. However, when I try calling it in the component file, I keep getting an error response ...

Having difficulty obtaining a delegation token through Auth0

I am currently working on an Angular2 application and I have integrated Auth0 for authentication. I successfully set up my Auth0 service by following the example provided here. However, I am facing an issue with obtaining a delegation token from Auth0 to ...

Protractor tests encountering failure due to the absence of any value in the model

A sample fiddle is being tested using Protractor. Here are the test cases: describe("Fiddle homepage", function() { beforeEach(function() { browser.get('http://fiddle.jshell.net/yfUQ8/9/show'); browser.rootEl = 'div&a ...

using node js to make an angular http get request

When working with MongoDB, I am able to query data and then send it as JSON to a specific URL. In the process of querying data from MongoDB router.get('fillSurvey/:ID', function (req, res) { Survey.findOne({_id:req.params.ID}, function ( ...