I am trying to create Angular2 project using angular-cli. I run, npm install -g angular-cli
then I ng new test
, it returns
"'ng' is not recognized as an interal or external command, operable program or batch file."
I check the directory, C:\\node\\node_modules\\npm\\node_modules
. There was not angular-cli found. My npm version is 4.0.2 and my node version is 5.11.0. If you guys have same problem, could you help me how to figure this out?
From angular-cli docs
Prerequisites
Both the CLI and generated project have dependencies that require Node 6.9.0 or higher, together with NPM 3 or higher.
You need to upgrade your node and npm first.
1) As VadimB suggested, you need to upgrade node and npm versions. Install latest version of node from nodejs.org and make sure you choose minimum Node 6.9.0 setup.
2) You are trying to run wrong command. Current version command is - npm install -g @angular/cli
(Please note - @ before angular/cli package in above command.)
3) After @angular/cli
installation, you can use ng help
or ng -v
to check successful installation and version.
4) You are looking at wrong folder. Once installed successfully, @angular\\cli
will be available in C:\\Users\\<UserName>\\AppData\\Roaming\\npm\\node_modules\\
Installing Angular Dependencies
node -v
npm install -g typescript
npm install -g @angular/cli
Angular
is a component oriented framework. Many components needs to be created to make the whole application. A component is a group of custom elements, HTML
elements, ShadowDOM
& HTML
imports.
Creating the Angular 4 app using Angular CLI
To create a fresh new Angular 4 app, use command ng new newAppName
. This command takes some time to execute.
package.json
- takes care of the development and app dependencies / packages / commands to execute
src\\main.ts
- takes care of the scaffolding the entire
src\\app\\app.module.ts
- any newly created module has to added to the declarations
and services has to be provided to the providers
key parameter of the function @NgModule
to make them accessible across the entire application
Run the Angular 4 app using Angular CLI
To run the freshly created app using CLI, use command ng serve
which will run the app on http://localhost:4200/ .
使用此代码:
npm install -g @angular/cli
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.