How to set up an Angular 2 project with Typescript in < 10 minutes.
Angular 2 is greatly designed to co-operate with typescript and nativescript. I won’t focus on nativescript, but briefly it has great support if you want to develop for mobile using Angular 2.
Typescript is being used to write Javascript (after processing) but it has got support for types, classes and more.
Back to our Angular 2 set up:
First you’ll need Node.js installed - depending on what system you’re using (Windows, Linux or Mac) there are different steps - please follow nodejs.
After you’ve got that set up open your Terminal or Command Line and run:
Angular provides a command line utility tool called Angular CLI - it’s great, it lets you add components and all their dependencies (to ng-module for example) automatically. To install it just type:
After a long install, if using Linux or Mac, you might get an error regarding watchman - it is used to observe changes in your files and restarting the server running your app - something like nodeman for node.js apps. To install it just run:
As you can see this time we’re using brew for installation (previously npm). If you haven’t got homebrew installed run:
And finally everything is ready!
We’ve got:
- Node.js
- npm (part of node)
- typescript
- watchman
- homebrew
Now we can finally build our first Angular 2 project using Angular CLI.
Enter your project or documents directory and run:
This will get your project build and configured, next enter the hello-world-angular2 directory.
You can review your app directory using:
- tree -F comnmand - it’ll show you what’s been created
And finally we’re ready to run our app! Run the following in the app directory:
Ta da! In the browser open http://localhost:4200
Your’re app is up and running!