Reputation: 2494
In Angular2 my getting problem to load internal ts file. inside main.ts i am calling app.component.
Errors are Failed to load resource: the server responded with a status of 404 (Not Found)
Error: XHR error (404 Not Found) loading http://localhost:12228/app/app.component(…)
http://localhost:12228/node_modules/angular2/platform/browser Failed to load resource: the server responded with a status of 500 (Internal Server Error)
Main.ts
import {bootstrap} from '../node_modules/angular2/platform/browser';
import {AppComponent} from './app.component';
bootstrap(AppComponent);
app.component.ts
import {Component} from '../node_modules/angular2/core';
@Component({
selector: 'hello-world',
template: '<h1>Hello World From www.angulartypescript.com</h1><h2>Hallo</h2>'
})
export class AppComponent { }
Index.html
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
<!--<script src="https://code.angularjs.org/2.0.0-beta.9/angular2-polyfills.js"></script>-->
<script src="https://code.angularjs.org/tools/system.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/2.0.0-beta.8/angular2.dev.js"></script>
<script src="https://code.angularjs.org/tools/typescript.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/angular2.min.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/http.min.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.9/router.dev.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/json2/20110223/json2.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.3.1/underscore-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone.js/0.9.2/backbone-min.js"></script>
<script src="http://cdnjs.cloudflare.com/ajax/libs/backbone-localstorage.js/1.0/backbone.localStorage-min.js"></script>
<script>
System.config({
map: {
app: 'assets/js/app'
},
packages: {
app: {
defaultExtension: 'js',
format: 'register'
}
}
});
System.import('app/main').then(null, console.error.bind(console));
</script>
<!--<script src="../node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="../node_modules/angular2/bundles/angular2-polyfills.min.js"></script>
<script src="../node_modules/angular2/bundles/angular2.dev.js"></script>
<script src="../node_modules/angular2/bundles/angular2.js"></script>
<script src="../node_modules/angular2/bundles/angular2.min.js"></script>-->
<!-- 2. Configure SystemJS -->
</head>
<!-- Run the application -->
<body>
<h1>Angular 2 Form builder </h1>
<hello-world>Loading Sample...</hello-world>
</body>
</html>
Please suggest me how to solve this. Thanks
Upvotes: 3
Views: 19794
Reputation: 19
If you are running your application in Visual Studio change the
import {AppComponent } from './app.component'
to
import { AppComponent } from './app.component.js'
Also change the file extension to .js. and make sure that your file "URL" points to the file.
Upvotes: 0
Reputation: 31
I encountered the similar problem. After spending about 3 hours, I realized I was running the ng serve
command in wrong directory.
Just check your present working directory before starting the angular project.
Upvotes: 1
Reputation: 202138
You should use:
import {bootstrap} from 'angular2/platform/browser'; // <----
import {AppComponent} from './app.component';
bootstrap(AppComponent);
and
import {Component} from 'angular2/core'; // <----
@Component({
selector: 'hello-world',
template: '<h1>Hello World From www.angulartypescript.com</h1><h2>Hallo</h2>'
})
export class AppComponent { }
because these modules are explicitly registered by the files you import (https://code.angularjs.org/2.0.0-beta.9/angular2.min.js
)
Upvotes: 3