Reputation: 13713
We are trying to start a new Angular project with Visual Studio 2015. We've created a new TypeScript project, and following an example we found we have put the followings in our index.html
file:
<script src="https://rawgithub.com/systemjs/systemjs/0.19.6/dist/system.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2-polyfills.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/Rx.js"></script>
<script src="https://code.angularjs.org/2.0.0-beta.0/angular2.dev.js"></script>
(sidenode - why do we need to many includes? what each means and why not have all of them in a single base file?)
our Angular app looks like this:
import {Component} from 'angular2/core';
@Component({
// Declare the tag name in index.html to where the component attaches
selector: 'hello-world',
// Location of the template for this component
templateUrl: 'app/hello_world.html'
})
export class HelloWorld {
// Declaring the variable for binding with initial value
yourName: string = '';
}
We wanted to add a type file for Angular from definitelytyped but it seems like it's empty (https://github.com/DefinitelyTyped/DefinitelyTyped/blob/master/angular2/angular2.d.ts). We also installed it from nuget (https://www.nuget.org/packages/angular2.TypeScript.DefinitelyTyped/) and got the same empty file - maybe it's not keeping up with Angular development?
Error TS1148 Cannot compile modules unless the '--module' flag is provided. Angular2TS_Test c:\Users\Ophir_O\documents\visual studio 2015\Projects\Angular2TS_Test\Angular2TS_Test\app\app.ts 3 Active
Error TS2307 Cannot find module 'angular2/core'. Angular2TS_Test c:\Users\Ophir_O\documents\visual studio 2015\Projects\Angular2TS_Test\Angular2TS_Test\app\app.ts 3 Active
Error Build: Argument of type '{ selector: string; templateUrl: string; }' is not assignable to parameter of type '{ selector: string; properties?: Object; hostListeners?: Object; injectables?: List<any>; lifecyc...'. Angular2TS_Test c:\users\ophir_o\documents\visual studio 2015\Projects\Angular2TS_Test\Angular2TS_Test\app\app.ts 9
Error Build: Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. Angular2TS_Test c:\users\ophir_o\documents\visual studio 2015\Projects\Angular2TS_Test\Angular2TS_Test\app\app.ts 12
Error TS1219 Experimental support for decorators is a feature that is subject to change in a future release. Specify '--experimentalDecorators' to remove this warning. Angular2TS_Test c:\Users\Ophir_O\documents\visual studio 2015\Projects\Angular2TS_Test\Angular2TS_Test\app\app.ts 12 Active
What is to correct current way to start an Angular project with TypeScript and VisualStudio? we couldn't find any up-to-date guide...
Upvotes: 1
Views: 4108
Reputation: 52847
Your component implementation looks fine.
To integrate with VS2015, follow these instructions from the accepted answer:
cannot find module 'angular2/core'
Your script should look like this:
<!-- 1. Load libraries -->
<script src="node_modules/es6-shim/es6-shim.js"></script>
<script src="node_modules/systemjs/dist/system.js"></script>
<script src="node_modules/typescript/lib/typescript.js"></script>
<script src="node_modules/angular2/bundles/angular2-polyfills.js"></script>
<script src="node_modules/rxjs/bundles/Rx.js"></script>
<script src="node_modules/angular2/bundles/angular2.dev.js"></script>
<!-- 2. Configure SystemJS -->
<script>
System.config({
transpiler: 'typescript',
typescriptOptions: { emitDecoratorMetadata: true },
packages: {'app': {defaultExtension: 'ts'}}
});
</script>
<!-- 3. Bootstrap -->
<script>
System.import('app/boot')
.then(null, console.error.bind(console));
</script>
HTML
<!-- 4. Display the application -->
<body>
<hello-world>Loading...</hello-world>
</body>
Create an app
folder. Inside the app
folder, add a boot.ts
and an helloworld.component.ts
.
app/boot.ts
import { bootstrap } from 'angular2/platform/browser';
import { HelloWorld } from './helloworld.component';
bootstrap(HelloWorld);
app/helloworld.component.ts
import {Component} from 'angular2/core';
@Component({
// Declare the tag name in index.html to where the component attaches
selector: 'hello-world',
// Location of the template for this component
templateUrl: './hello_world.html'
})
export class HelloWorld {
// Declaring the variable for binding with initial value
yourName: string = '';
}
Upvotes: 2
Reputation: 826
Here is a link to a seed project with the minimum requirements and code for Angular 2. Angular 2 seed project for Visual Studio 2015
2 things are important though:
1 - configuring IIS to server the project
2 - downloading the latest nodejs (with the latest npm), after node is installed - set VS2015 "External Web Tools" (you can find it in quick launch) to use the nodejs location (for me the default was "c:\Program Files\nodejs") and take it to the first priority using the up arrow.
Upvotes: 0
Reputation: 706
You need to add a tsconfig.json
file that tells the TypeScript compiler how to compile your code for Angular2. See: https://github.com/mgechev/angular2-seed/blob/master/tsconfig.json
Upvotes: 0