Angular is a platform that makes it easy to build an application in the web. Angular turns your template into codes that are highly optimized for Javascript. It quickly creates UI views with simple and powerful template syntax. Here we will be discussing on how to set up Angualr 2 in Visual Studio.
In order to install the Angular 2 the first thing we need is to install Node.js. This can be installed from the following link https://nodejs.org/en/download/ .We can choose 32-bit or 64-bit according to our system configuration.
We can check if it is already installed checking the version of node.js in the command prompt.
If it is not installed we will be getting an error message saying node is not recognized as an internal or external command. Next step is to create a new project in visual studio.Then we have to configure the environment settings for node and npm.
This tells Visual Studio to look for external tools (like npm) in the global path before the internal path.
The next thing we have to do is install typescript for visual studio. Typescript is designed for development of large applications and trans-compiles to JavaScript.
Now we have to download the Quick Start Files from the Angular web site using the link below.
Extract the contents of the downloaded .ZIP folder. https://github.com/angular/quickstart
Copy the required files from the unzipped folder which includes
- src
- bs-config.json
- package.json
- tslint.json
Copy the above folders and files into the solution and include it in the project.Then we have to restore the packages. In order to do that we have to right click the package.json file and then click the Restore Packages
This will result in the installation of all the node_modules.You can check the output window to find out whether it has been restored correctly or not.
We don’t have to include the node modules in the project.Now the installation is completed and we can run the project using npm start but not through visual studio. In order to start the project with visual studio we need some more configurations to do. Notice that in the browser when we clicking F12 we have 404 not found errors for the following sites
- styles.css
- systemjs.config.js
- main.js
All these files are present in “src” folder. So to fix these “404 Not Found” errors, in index.html file, change <base href=”/”> to <base href=”/src/”>
and we have to include “/” before node_modules
At this point reload the page and you will see “Hello Angular” message without any errors.
If you want Visual Studio to compile Typescript to JavaScript when the changes are saved, we need to turn this feature “ON” by including the following setting in tsconfig.json file
Happy coding 🙂