[英]How do I install Angular 2 using NPM?
I'm trying to setup my own local development environment for an Angular 2 app without using the QuickStart seed mentioned in the Angular 2 site or the Angular CLI because they tend to come with extra files that I don't really require.我正在尝试为 Angular 2 应用程序设置我自己的本地开发环境,而不使用 Angular 2站点或Angular CLI 中提到的 QuickStart 种子,因为它们往往带有我并不真正需要的额外文件。
Now, everything's going fine except that I don't know how to get Angular 2 using NPM.现在,一切都很顺利,只是我不知道如何使用 NPM 获得 Angular 2。 I've tried using npm install angular2 --save
but I just found out that angular2 has been deprecated and was a pre-release version.我试过使用npm install angular2 --save
但我刚刚发现 angular2 已被弃用并且是一个预发布版本。 So I guess how do I get the latest Angular 2.0 plugins using NPM, if at all possible at the moment?所以我想我如何使用 NPM 获取最新的 Angular 2.0 插件,如果可能的话?
at https://angular.io/docs/ts/latest/guide/setup.html , is recommended to use QuickStart seed, here is its package.json , so actually we need to download its dependencies:在https://angular.io/docs/ts/latest/guide/setup.html ,推荐使用 QuickStart 种子,这里是它的package.json ,所以实际上我们需要下载它的依赖项:
"dependencies": {
"@angular/common": "~2.4.0",
"@angular/compiler": "~2.4.0",
"@angular/core": "~2.4.0",
"@angular/forms": "~2.4.0",
"@angular/http": "~2.4.0",
"@angular/platform-browser": "~2.4.0",
"@angular/platform-browser-dynamic": "~2.4.0",
"@angular/router": "~3.4.0",
"angular-in-memory-web-api": "~0.2.4",
"systemjs": "0.19.40",
"core-js": "^2.4.1",
"rxjs": "5.0.1",
"zone.js": "^0.7.4"
}
you could also create your custom package.json , by running npm init
, copying these dependencies (or most of them) and than running npm install
with your package.json您还可以创建您的自定义package.json ,通过运行npm init
,复制这些依赖项(或其中大部分),然后使用您的 package.json 运行npm install
Angular 4 could be installed in two ways: Angular 4可以通过两种方式安装:
Note: Make sure your system already installed node js and npm注意:确保你的系统已经安装了 node js 和 npm
1. Cloning : 1. 克隆:
Suppose you want to make a project named helloworld, then run the following commands from your terminal假设您要创建一个名为 helloworld 的项目,然后从终端运行以下命令
git clone https://github.com/angular/quickstart.git helloworld
cd helloworld
npm install
npm start
After running last command you could see from your browser like this运行最后一个命令后,您可以像这样从浏览器中看到
2. Downloading : 2.下载:
Download the QuickStart seed and unzip it into your project folder.下载QuickStart 种子并将其解压缩到您的项目文件夹中。 Then perform the below steps with terminal commands.然后使用终端命令执行以下步骤。
cd quickstart
npm install
npm start
For more details go to official site欲了解更多详情,请访问官方网站
Paste the below code into a file by creating and naming it as package.json .通过创建并将其命名为package.json将以下代码粘贴到文件中。
{ "name": "demo-app", "version": "1.0.0", "author": "Aravind", "description": "set up files for the first Demo App", "scripts": { "start": "tsc && concurrently \\"tsc -w\\" \\"lite-server\\" ", "tsc": "tsc", "tsc:w": "tsc -w", "lint": "tslint ./app/**/*.ts -t verbose", "lite": "lite-server", "typings": "typings", "postinstall": "typings install" }, "license": "ISC", "dependencies": { "@angular/common": "2.0.0", "@angular/compiler": "2.0.0", "@angular/core": "2.0.0", "@angular/forms": "2.0.0", "@angular/http": "2.0.0", "@angular/platform-browser": "2.0.0", "@angular/platform-browser-dynamic": "2.0.0", "@angular/router": "3.0.0", "core-js": "^2.4.1", "reflect-metadata": "^0.1.3", "rxjs": "5.0.0-beta.12", "systemjs": "0.19.27", "zone.js": "^0.6.23", "bootstrap": "^3.3.6" }, "devDependencies": { "concurrently": "^2.2.0", "lite-server": "^2.2.0", "tslint": "^3.7.4", "typescript": "^2.0.2", "typings": "^1.0.4" }, "repository": {} }
navigate to the root folder in Cmd and导航到 Cmd 中的根文件夹,然后
npm install or npm i
Alternatively if you want to create a new package.json或者,如果你想创建一个新的package.json
Execute the command执行命令
npm init
This will create a new package.json file and copy paste the above code to install angular2 along with few other basic dependencies.这将创建一个新的package.json文件并复制粘贴上述代码以安装 angular2 以及其他一些基本依赖项。
If you are looking for a simple set up.如果您正在寻找一个简单的设置。 Have a look at this post .看看这个帖子。
It depend on your build tool, if it is webpack, you need just install angular components, like:这取决于你的构建工具,如果是 webpack,你只需要安装 angular 组件,例如:
"dependencies": {
"@angular/common": "~4.0.0",
"@angular/compiler": "~4.0.0",
"@angular/core": "~4.0.0",
"@angular/forms": "~4.0.0",
"@angular/http": "~4.0.0",
"@angular/platform-browser": "~4.0.0",
"@angular/platform-browser-dynamic": "~4.0.0",
"@angular/router": "~4.0.0"
}
And all additional vendor modules if it needed in your case.以及所有其他供应商模块(如果您的情况需要)。
npm uninstall –g @angular/cli
卸载最新版本的 CLI > npm uninstall –g @angular/cli
npm cache clean
清理缓存 > npm cache clean
npm install –g @angular/cli@1.1.3
安装特定版本的 angular CLI > npm install –g @angular/cli@1.1.3
cd project_name
导航到项目文件夹位置 > cd project_name
npm i codemirror
npm i ng2-codemirror
npm i ng2-split-pane
npm i ng2-daterange-picker
npm install
运行npm install
ng serve
最后做 > ng serve
Installing Angular Dependencies安装 Angular 依赖项
node -v
安装稳定版本的Node (如果尚未安装)并使用node -v
验证安装npm install -g typescript
使用命令npm install -g typescript
安装TypeScriptnpm install -g @angular/cli
使用命令npm install -g @angular/cli
下载并安装Angular CLI Angular
is a component oriented framework. Angular
是一个面向组件的框架。 Many components needs to be created to make the whole application.需要创建许多组件来构建整个应用程序。 A component is a group of custom elements, HTML
elements, ShadowDOM
& HTML
imports.组件是一组自定义元素、 HTML
元素、 ShadowDOM
和HTML
导入。
Navigate to the root folder in Cmd.导航到 Cmd 中的根文件夹。
$ cd myproject
Execute the command执行命令
$ npm install $ npm start
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.