angular 命令行项目_Angular命令行界面介绍
angular 命令行项目
Angular is closely associated with its command-line interface (CLI). The CLI streamlines generation of the Angular file system. It deals with most of the configuration behind the scenes so developers can start coding. The CLI also has a low learning curve recommendable for any newcomer wanting to jump right in. Heck, even experienced Angular developers rely on the CLI!
Angular与它的命令行界面(CLI)紧密相关。 CLI简化了Angular文件系统的生成。 它处理了幕后的大多数配置,因此开发人员可以开始编码。 CLI的学习曲线也很低,对于任何想马上加入的新手来说都是值得推荐的。
安装 (Installation)
The Angular CLI requires Node.js and Node Packet Manager (NPM). You can check for these programs with the terminal command: node -v; npm -v
. Once installed, open a terminal and install the Angular CLI with this command: npm install -g @angular/cli
. This can executed from anywhere on your system. The CLI is configured for global use with the -g
flag.
Angular CLI需要Node.js和Node Packet Manager(NPM) 。 您可以使用以下终端命令检查这些程序: node -v; npm -v
node -v; npm -v
。 安装完成后,打开终端并使用以下命令安装Angular CLI: npm install -g @angular/cli
。 这可以在系统上的任何位置执行。 通过-g
标志将CLI配置为全局使用。
Verify the CLI is there with the command: ng -v
. This outputs several lines of information. One of these lines state the version of the installed CLI.
使用以下命令验证CLI是否存在: ng -v
。 这将输出几行信息。 这些行之一表明已安装的CLI的版本。
Recognize that ng
is the basic building block of the CLI. All your commands will begin with ng
. Time to take a look at four of the most common commands prefixed with ng
.
认识到ng
是CLI的基本构建块。 您所有的命令都将以ng
开头。 是时候来看一下以ng
开头的四个最常见的命令了。
按键命令 (Key Commands)
- ng newng新
- ng serveng服务
- ng generateng产生
- ng buildng构建
- ng updateng更新
The key terms for each of these are quite telling. Together, they comprise what you will need to hit the ground running with Angular. Of course, there are many more. All commands are outlined in the CLI’s GitHub Documentation1. You will likely find that the commands listed above will cover the necessary bases.
这些中的每一个的关键术语都非常有说服力。 它们共同构成了您使用Angular运行时所需的条件。 当然,还有更多。 CLI的GitHub文档1中概述了所有命令。 您可能会发现上面列出的命令将涵盖必要的基础。
ng新 (ng new)
ng new
creates a new Angular file system. This is a surreal process. Please navigate to a file location desirable for new application generation. Type this command as follows, replacing [name-of-app]
with whatever you want: ng new [name-of-app]
.
ng new
创建一个新的 Angular文件系统。 这是一个超现实的过程。 请导航到生成新应用程序所需的文件位置。 键入以下命令,将[name-of-app]
替换[name-of-app]
您想要的任何内容: ng new [name-of-app]
。
A file system under the folder [name-of-app]
should appear. Feel free to explore what lies within. Try to not make any changes yet. All of what you need to run your first Angular application comes packaged together in this generated file system.
应显示文件夹[name-of-app]
下的文件系统。 随意探索其中的内容。 尝试不做任何更改。 运行第一个Angular应用程序所需的所有内容都打包在此生成的文件系统中。
ng服务 (ng serve)
To get the application running, the ng serve
command must execute within the [name-of-app]
folder. Anywhere within the folder will do. The Angular CLI must recognize that it is within an environment generated with ng new
. It will run provided this one condition. Go ahead and try it: ng serve
.
要使应用程序运行,必须在[name-of-app]
文件夹中执行ng serve
命令。 文件夹中的任何位置都可以。 Angular CLI必须认识到它在ng new
生成的环境中。 只要满足这一条件,它将运行。 继续尝试: ng serve
。
The application runs on port 4200 by default. You can view the Angular application by navigating to localhost:4200
in any web browser. Angular works across all browsers. Unless you are using an old version of Internet Explorer, the application will pop up. It displays the official Angular logo alongside a list of helpful links.
默认情况下,该应用程序在端口4200上运行。 您可以通过在任何Web浏览器中导航到localhost:4200
来查看Angular应用程序。 Angular可在所有浏览器中使用。 除非您使用旧版本的Internet Explorer,否则将弹出该应用程序。 它显示官方的Angular徽标以及有用的链接列表。
Ok, the application runs. It hopefully functions, but you need to know what is going on under the hood. Refer back to the [name-of-app]
file system. Navigate [name-of-app] -> src -> app
. Therein lies the files responsible for what you saw on localhost:4200
.
好的,应用程序运行。 它有望发挥作用,但您需要了解引擎盖下正在发生的事情。 返回参考[name-of-app]
文件系统。 浏览[name-of-app] -> src -> app
。 这些文件负责您在localhost:4200
上看到的内容。
ng产生 (ng generate)
The .component
files define an Angular component including its logic (.ts
), style (.css
), layout (.html
), and testing (.spec.ts
). The app.module.ts
particularly stands out. Together, these two groups of files work together as component
and module
. Both component
and module
are two separate examples of Angular schematics. Schematics classify the different purpose-driven blocks of code generatable with ng generate
.
.component
文件定义了一个Angular组件,包括其逻辑( .ts
),样式( .css
),布局( .html
)和测试( .spec.ts
)。 app.module.ts
特别突出。 这两组文件一起作为component
和module
一起工作。 component
和module
都是Angular原理图的两个单独示例。 原理图分类代码能发生的不同目的导向块与ng generate
。
For the sake of this article, understand that a module
exports and imports assets to and from an underlying component tree. A component
concerns itself with one section of the user interface. That unit’s logic, style, layout, and testing stays encapsulated within the various .component
files.
为了本文的目的,请理解module
将资产导入到底层组件树或从底层组件树导入资产。 component
与用户界面的一部分有关。 该单元的逻辑,样式,布局和测试始终封装在各种.component
文件中。
As for ng generate
, this command can generate skeletons for each of the available Angular schematics2. Navigate to [name-of-app -> src -> app]
. Try generating a new component
by executing: ng generate component [name-of-component]
. Replace [name-of-component]
with whatever you would like. A new file [name-of-component]
will pop up along with its necessary component
files.
至于ng generate
,此命令可以为每个可用的Angular原理图2生成骨架。 导航到[name-of-app -> src -> app]
。 尝试通过执行以下操作来ng generate component [name-of-component]
新component
: ng generate component [name-of-component]
。 用任何您想要的替换[name-of-component]
。 将会弹出一个新文件[name-of-component]
及其必需的component
文件。
You can see that ng generate
expedites Angular’s boilerplate code. ng generate
also wires things up. Schematics created within context of an Angular file system connect with the system’s root module. In this case, that would be app.module.ts
file inside [name-of-app -> src -> app]
.
您会看到ng generate
expedites Angular的样板代码 。 ng generate
也会把东西连接起来。 在Angular文件系统的上下文中创建的示意图与系统的根模块连接。 在这种情况下,这将是[name-of-app -> src -> app]
app.module.ts
[name-of-app -> src -> app]
app.module.ts
文件。
ng构建 (ng build)
Angular is a front end tool. The CLI performs its operations on behalf of the front end. ng serve
takes care of the back end server setup. This keeps development entirely focused on the front end. That said, connecting your own back end to the Angular application must also be possible.
Angular是一种前端工具。 CLI代表前端执行其操作。 ng serve
负责后端服务器的设置。 这使开发完全集中在前端。 也就是说,还必须将自己的后端连接到Angular应用程序。
ng build
fulfills this need. Before trying it out inside of the file system. Navigate to [name-of-app] -> angular.json
. Look for this single line of code: "outputPath": "dist/my-app"
.
ng build
满足了这一需求。 在文件系统内部尝试之前。 导航至[name-of-app] -> angular.json
。 查找以下单行代码: "outputPath": "dist/my-app"
。
This one line of configuration determines where ng build
dumps its results. The results being the entire Angular application compiled into one folder dist/my-app
. Inside of that folder, there exists index.html
. The whole Angular application can run with index.html
. No ng serve
is necessary from here. With this file, you can easily wire up your back end.
这一行配置确定ng build
将结果转储到何处。 结果是将整个Angular应用程序编译到一个文件夹dist/my-app
。 在该文件夹中,存在index.html
。 整个Angular应用程序都可以使用index.html
运行。 从这里不需要ng serve
。 使用此文件,您可以轻松地连接后端。
Give it a go: ng build
. Again, this must execute within the Angular file system. Based of the key value of “outputPath:”
in angular.json
. A file will generate wherein the original application is fully compiled. If you kept “outputPath:”
the same, the compiled application will be in: [name-of-app] -> dist -> [name-of-app]
.
尝试一下: ng build
。 同样,这必须在Angular文件系统中执行。 基于angular.json
中“outputPath:”
的angular.json
。 将生成一个文件,其中原始应用程序已完全编译。 如果您将“outputPath:”
保持不变, “outputPath:”
编译的应用程序将位于: [name-of-app] -> dist -> [name-of-app]
。
ng更新 (ng update)
In angular cli ng update do automatic updation on all the angular and npm packages to latest versions.
在角度更新中,将所有角度和npm软件包自动更新到最新版本。
Here is the syntax and options can be used with ng update
.
这是ng update
可以使用的语法和选项。
ng update [package]
ng update [package]
选件 (Options)
dry-run
--dry-run (alias: -d)
空运行-
--dry-run (alias: -d)
Run through without making any changes.
无需进行任何更改即可运行。
force
--force
力
--force
If false, will error out if installed packages are incompatible with the update.
如果为false,如果已安装的软件包与更新不兼容,则会出错。
all
--all
所有
--all
Whether to update all packages in package.json.
是否更新package.json中的所有软件包。
next
--next
未来
--next
Use the largest version, including beta and RCs.
使用最大的版本,包括beta和RC。
migrate-only
--migrate-only
迁移只
--migrate-only
Only perform a migration, does not update the installed version.
仅执行迁移,不会更新已安装的版本。
from
--from
从
--from
从Version from which to migrate from. Only available with a single package being updated, and only on migration only.
从其迁移的版本。 仅在更新单个程序包时才可用,并且仅在迁移时才可用。
to
--to
到
--to
Version up to which to apply migrations. Only available with a single package being updated, and only on migrations only. Requires from to be specified. Default to the installed version detected.
应用迁移的版本。 仅在更新单个程序包时才可用,并且仅在迁移时才可用。 需要从指定。 默认为检测到的安装版本。
registry
--registry
注册表
--registry
The NPM registry to use.
要使用的NPM注册表。
These commands cover the basics. Angular’s CLI is an incredible convenience that expedites application generation, configuration, and expansion. It does all this while maintaining flexibility, allowing the developer to make necessary changes.
这些命令涵盖了基础知识。 Angular的CLI是令人难以置信的便利,可加快应用程序的生成,配置和扩展。 它在保持灵活性的同时做到了所有这些,使开发人员可以进行必要的更改。
Please check out those links on localhost:4200
if you have not already. Do not forget to run ng serve
before opening it up. With a better understanding of the CLI, you are now ready to learn more about what is generated by its most essential commands.
如果尚未localhost:4200
请在localhost:4200
上查看这些链接。 不要忘了运行ng serve
打开它之前。 在对CLI有了更好的了解之后,您现在就可以了解有关其最基本命令所生成内容的更多信息。
更多信息: (More information:)
The Best Angular Examples
最佳角度示例
The Best Angular and AngularJS Tutorials
最好的Angular和AngularJS教程
How to Validate Angular Reactive Forms
如何验证角React形式
翻译自: https://www.freecodecamp.org/news/angular-command-line-interface-explained/
angular 命令行项目
相关文章:
oracle-imp导入小错filesize设置
***********************************************声明*********************************************************************** 原创作品,出自 “深蓝的blog” 博客。欢迎转载,转载时请务必注明出处。否则追究版权法律责任。表述有错误之处…

CentOS 7 下用 firewall-cmd / iptables 实现 NAT 转发供内网服务器联网
自从用 HAProxy 对服务器做了负载均衡以后,感觉后端服务器真的没必要再配置并占用公网IP资源。 而且由于托管服务器的公网 IP 资源是固定的,想上 Keepalived 的话,需要挤出来 3 个公网 IP 使用,所以更加坚定了让负载均衡后端服务器…

八皇后的一个回溯递归解法
解法来自严蔚敏的数据结构与算法。 代码如下: #include <iostream> using namespace std; const int N 8;//皇后数 int count 0;//解法统计 int a[N][N];//储存值的数组const char *YES "■"; const char *NO "□"; //const char *Y…

即时编译和提前编译_即时编译说明
即时编译和提前编译Just-in-time compilation is a method for improving the performance of interpreted programs. During execution the program may be compiled into native code to improve its performance. It is also known as dynamic compilation.即时编译是一种提…

bzoj 2588 Spoj 10628. Count on a tree (可持久化线段树)
Spoj 10628. Count on a tree Time Limit: 12 Sec Memory Limit: 128 MBSubmit: 7669 Solved: 1894[Submit][Status][Discuss]Description 给定一棵N个节点的树,每个点有一个权值,对于M个询问(u,v,k),你需要回答u xor lastans和v这两个节点…

.Net SqlDbHelper
using System.Configuration; using System.Data.SqlClient; using System.Data;namespace ExamDAL {class SqHelper{#region 属性区// 连接字符串private static string strConn;public static string StrConn{get{return ConfigurationManager.ConnectionStrings["Exam&…

C语言的一个之前没有见过的特性
代码: #include <stdio.h>int test(){int a ({int aa 0;int bb 1;int cc 2;if(aa 0 && bb 1)printf("aa %d, bb %d\n", aa, bb);//return -2;cc;});return a; }int main(){typeof(4) a test();printf("a %d\n", a); } …

如何构建顶部导航条_如何构建导航栏
如何构建顶部导航条导航栏 (Navigation Bars) Navigation bars are a very important element to any website. They provide the main method of navigation by providing a main list of links to a user. There are many methods to creating a navigation bar. The easiest…

SPSS聚类分析:K均值聚类分析
SPSS聚类分析:K均值聚类分析 一、概念:(分析-分类-K均值聚类) 1、此过程使用可以处理大量个案的算法,根据选定的特征尝试对相对均一的个案组进行标识。不过,该算法要求您指定聚类的个数。如果知道ÿ…

[ 总结 ] nginx 负载均衡 及 缓存
操作系统:centos6.4 x64 前端使用nginx做反向代理,后端服务器为:apache php mysql 1. nginx负载均衡。 nginx编译安装(编译安装前面的文章已经写过)、apache php mysql 直接使用yum安装。 nginx端口:80…

中国剩余定理(孙子定理)的证明和c++求解
《孙子算经》里面的"物不知数"说的是这样的一个题目:一堆东西不知道具体数目,3个一数剩2个,5个一数剩3个,7个一数剩2个,问一共有多少个。 书里面给了计算过程及答案:70*2 21*3 15*2 -105*2 2…

osi七层网络层_OSI层速成课程
osi七层网络层介绍 (Introduction) Have you ever wondered how data is sent through the network from one machine to another? If yes, then the Open System Interconnected model is what you are looking for.您是否曾经想过如何通过网络将数据从一台机器发送到另一台机…

KMP算法求回溯数组的步骤
KMP算法到底是什么原理就不说了,各种资料上讲的明明白白,下面我就如何用代码来实现做一下说明和记录. KMP的核心思想就是,主串不回溯,只模式串回溯。而模式串匹配到第几位时失配,要回溯多少,由模式串本身来…
【.Net】vs2017 自带发布工具 ClickOnce发布包遇到的问题
一、遇到的问题 在安装了vs2017 社区版(Community)之后 想打包安装程序(winform) 还是想用之前的 installshield来打包 发现居然打不了,在官网查了 installshield不支持社区版(Community)&…

windows平台,开发环境变量配置
1.打开我的电脑--属性--高级--环境变量 JAVA配置环境变量变量名:JAVA_HOME 变量值:C:\Program Files\Java\jdk1.7.0 变量名:CLASSPATH 变量值:.;%JAVA_HOME%\lib\dt.jar;%JAVA_HOME%\lib\tools.jar; 变量名:Path 变…

如何编写可测试的代码 哈利勒的方法论
Understanding how to write testable code is one of the biggest frustrations I had when I finished school and started working at my first real-world job. 当我完成学业并开始从事第一份现实世界的工作时,了解如何编写可测试的代码是我最大的挫败之一。 T…

【Java入门提高篇】Day6 Java内部类——成员内部类
内部类是什么,简单来说,就是定义在类内部的类(一本正经的说着废话)。 一个正经的内部类是长这样的: public class Outer {class Inner{} } 这是为了演示而写的类,没有什么luan用,可以看到Inner类…

POJ 1001(高精度乘法 java的2种解法)
方法1: import java.math.BigDecimal; import java.util.Scanner; public class Main {public static void main(String[] args) {Scanner sc new Scanner(System.in);while(sc.hasNext()){String d sc.next();int z sc.nextInt();BigDecimal bd new BigDecimal(d);BigDeci…

Java编写的电梯模拟系统《结对作业》
作业代码:https://coding.net/u/liyi175/p/Dianti/git 伙伴成员:李伊 http://home.cnblogs.com/u/Yililove/ 对于这次作业,我刚开始一点思绪都没有,在老师安排了结对伙伴李伊之后,我的搭档问我,我们需要什么…

HTML属性说明
HTML elements can have attributes, which contain additional information about the element.HTML元素可以具有属性,其中包含有关该元素的其他信息。 HTML attributes generally come in name-value pairs, and always go in the opening tag of an element. Th…

css中的选择器
1.在html中引入css的方法:四种方式: a.行内式(也称内联式) 如: <h1 style"color:red;test</h1> b.内嵌式 <style type"text/css"> h1{ color:red; font-size: 10.5pt; font-family: Calibri, sans-serif; line-height: normal; widow…

javascript的call()方法与apply()方法的理解
先看一段代码 function cat() {} cat.prototype{food:fish,say:function () {console.log(I love this.food);} };var blackCat new cat(); blackCat.say(); 这时,控制台输出 I love fish若此时,有另一个对象 Dog{food:bones and shit}; dog对象没有say…

java排序算法(冒泡,插入,选择,快速,堆,归并,希尔,基数)
import java.util.Arrays; import java.util.LinkedList;/*** * * 各种排序: 冒泡,插入,选择,快速,堆,归并,希尔,基数*/ public class Sorts {//1. 冒泡://时间复杂度:n(n-1)/2O(n^2…

边界填充算法讲解_边界填充算法
边界填充算法讲解Boundary fill is the algorithm used frequently in computer graphics to fill a desired color inside a closed polygon having the same boundary color for all of its sides.边界填充是在计算机图形学中经常使用的算法,用于在其所有边都具有…

使用Git管理源代码
git是个了不起但却复杂的源代码管理系统。它能支持复杂的任务,却因此经常被认为太过复杂而不适用于简单的日常工作。让我们诚实一记吧:Git是复杂的,我们不要装作它不是。但我仍然会试图教会你用(我的)基本的Git和远程代…

[.Net跨平台]部署DTCMS到Jexus遇到的问题及解决思路---Linux环境搭建
最近朋友托我帮忙研究如何把一个DTCMS部署到Linux下,经过1天的研究,部署基本成功,可能有些细节还未注意到,现在把心得分享一下。过程比预期的要简单 身为.Net程序员,这个问题的第一步可能就是如何搭建一个Linux环境来测…

Sequence point 中文
摘自维基百科: In C[4] and C,[5] sequence points occur in the following places. (In C, overloaded operators act like functions, and thus operators that have been overloaded introduce sequence points in the same way as function calls.) Between ev…

python中pop函数_Python中的Pop函数
python中pop函数什么是弹出功能? (What is the pop function?) The method pop() removes and returns the last element from a list. There is an optional parameter which is the index of the element to be removed from the list. If no index is specified…

第六周学习进度条
日期 任务 听课 编程 阅读 准备考试 日总计 周日 周一 120 300 0 0 420 100 周二 0 120 0 0 120 周三 0 0 0 0 0 周四 0 0 0 0 0 周五 0 0 0 0 0 周六 0 120 100 0 …

1071. 小赌怡情(15)
常言道“小赌怡情”。这是一个很简单的小游戏:首先由计算机给出第一个整数;然后玩家下注赌第二个整数将会比第一个数大还是小;玩家下注t个筹码后,计算机给出第二个数。若玩家猜对了,则系统奖励玩家t个筹码;…