1. Environment
setup feels that the installation and configuration is relatively cumbersome. Looking at the documentation from the rookie network, you must first install node.js, the latest version of node.js integrates npm, then use Taobao's npm mirror, and then install scaffolding. It seems that this process is very simple. But when I was looking for information, a lot of them were written, and they were not integrated. So I am equipped to write a concise version of the installation process blog.
-
Install node.Js
download address: http://nodejs.cn/download/
The computer where angular is installed must install the latest nodejs.
Check whether the installation is successful:
open the cmd command window and enter the command: node --version; as shown in the figure
-
Install the
new version of cnpm nodejs has integrated npm, so npm has been installed by the way. Because the domestic access of npm official website mirror is too slow, it will be faster to use Taobao’s npm mirror. When you can use npm later, try to use cnpm instead.
Cmd window installation command:
npm install -g cnpm --registry=https://registry.npm.taobao.org
Install angular scaffold
Cmd window installation command: cnpm install -g @angular/cli
View angular version
Cmd window installation command: ng --version The
appearance of the relevant version indicates that the angular environment is successfully built!
2.
Angular uses the command ng to create the project , so it is a combination of ng + other commands. I have seen a lot of versions of creating angular projects, and I feel that this version is quite good. It is recommended to use: Enter the command in the Cmd window: (You can first cd to a directory you specify and then create the project)
1.ng new demo1 --skip-install (Create angular project demo1 without using npm update)
2.cd demo1 (go to demo1 folder)
3.cnpm install (use cnpm update, faster)
4.ng serve (run) or ng serve --open (run and use The default browser is open)
The effect of running is like this: paste the access address to the browser to run the
initial project page
3. Errors that may be encountered when the Angular environment is set up and the project is created.
I made many mistakes when I created the project. Sometimes the project can’t run, so it’s very troublesome. Baidu posted a lot of mistakes before I knew some of them. According to my steps above, there should be no such mistakes. I put me wrong. The error is posted for reference (the solution is also obtained by Baidu).
-
npm failed to install angular/cli,
it is recommended to use cnpm to install -
When creating a project, npm install failed
to initialize the project. It is recommended to use cnpm install to initialize the project -
After creating a project with the project npm cnpm i I not run or
alternatively with CNPM and npm Yarn, steps
1 cnpm instal @ angular / cli
when 2 ng new ng prevents automatic installation package, creates only a directory ng
(ng new new command my-app --skip-install)
3 Install yarn npm install -g yarn / cnpm install -g yarn
4 Enter the directory my-app and use yarn to install the package yarn that ng depends on
Record, summarize, share! Learning is always on the way!