The Angular CLI is a command line interface tool
that can create a project, add files, and perform a variety of ongoing development tasks such
as testing, bundling, and deployment.
The goal in this guide is to build and run a simple Angular
application in TypeScript, using the Angular CLI
while adhering to the Style Guide recommendations that
benefit every Angular project.
By the end of the chapter, you'll have a basic understanding of development with the CLI
and a foundation for both these documentation samples and for real world applications.
我们通过下列三大步来达到目的:
You'll pursue these ends in the following high-level steps:
Verify that you are running at least node 6.9.x and npm 3.x.x
by running node -v and npm -v in a terminal/console window.
Older versions produce errors, but newer versions are fine.
The CLI created the first Angular component for you.
This is the root component and it is named app-root.
You can find it in ./src/app/app.component.ts.
打开这个组件文件,并且把title属性从 app works! 改为 My First Angular App :
Open the component file and change the title property from app works! to My First Angular App:
src/app/app.component.ts
exportclassAppComponent{
title ='My First Angular App';}
浏览器会自动刷新,而我们会看到修改之后的标题。不错,不过它还可以更好看一点。
The browser reloads automatically with the revised title. That's nice, but it could look better.
打开 src/app/app.component.css 并给这个组件设置一些样式
Open src/app/app.component.css and give the component some style.
The first file you should check out is README.md.
It has some basic information on how to use CLI commands.
Whenever you want to know more about how Angular CLI works make sure to visit
the Angular CLI repository and
Wiki.
有些生成的文件你可能觉得陌生。接下来我们就讲讲它们。
Some of the generated files might be unfamiliar to you.
Your app lives in the src folder.
All Angular components, templates, styles, images, and anything else your app needs go here.
Any files outside of this folder are meant to support building your app.
Defines the AppComponent along with an HTML template, CSS stylesheet, and a unit test.
It is the root component of what will become a tree of nested components
as the application evolves.
Defines AppModule, the root module
that tells Angular how to assemble the application.
Right now it declares only the AppComponent.
Soon there will be more components to declare.
assets/*
这个文件夹下你可以放图片等任何东西,在构建应用时,它们全都会拷贝到发布包中。
A folder where you can put images and anything else to be copied wholesale
when you build your application.
This folder contains one file for each of your destination environments,
each exporting simple configuration variables to use in your application.
The files are replaced on-the-fly when you build your app.
You might use a different API endpoint for development than you do for production
or maybe different analytics tokens.
You might even use some mock services.
Either way, the CLI has you covered.
favicon.ico
每个网站都希望自己在书签栏中能好看一点。
请把它换成你自己的图标。
Every site wants to look good on the bookmark bar.
Get started with your very own Angular icon.
The main HTML page that is served when someone visits your site.
Most of the time you'll never need to edit it.
The CLI automatically adds all js and css files when building your app so you
never need to add any <script> or <link> tags here manually.
The main entry point for your app.
Compiles the application with the JIT compiler
and bootstraps the application's root module (AppModule) to run in the browser.
You can also use the AOT compiler
without changing any code by passing in --aot to ng build or ng serve.
Different browsers have different levels of support of the web standards.
Polyfills help normalize those differences.
You should be pretty safe with core-js and zone.js, but be sure to check out
the Browser Support guide for more information.
Your global styles go here.
Most of the time you'll want to have local styles in your components for easier maintenance,
but styles that affect all of your app need to be in a central place.
test.ts
这是单元测试的主要入口点。
它有一些你不熟悉的自定义配置,不过你并不需要编辑这里的任何东西。
This is the main entry point for your unit tests.
It has some custom configuration that might be unfamiliar, but it's not something you'll
need to edit.
The src/ folder is just one of the items inside the project's root folder.
Other files help you build, test, maintain, document, and deploy the app.
These files go in the root folder next to src/.
Inside e2e/ live the End-to-End tests.
They shouldn't be inside src/ because e2e tests are really a separate app that
just so happens to test your main app.
That's also why they have their own tsconfig.e2e.json.
node_modules/
Node.js创建了这个文件夹,并且把package.json中列举的所有第三方模块都放在其中。
Node.js creates this folder and puts all third party modules listed in
package.json inside of it.
Configuration for Angular CLI.
In this file you can set several defaults and also configure what files are included
when your project is build.
Check out the official documentation if you want to know more.
Simple configuration for your editor to make sure everyone that uses your project
has the same basic configuration.
Most editors support an .editorconfig file.
See http://editorconfig.org for more information.
.gitignore
一个Git的配置文件,用来确保某些自动生成的文件不会被提交到源码控制系统中。
Git configuration to make sure autogenerated files are not commited to source control.
Basic documentation for your project, pre-filled with CLI command information.
Make sure to enhance it with project documentation so that anyone
checking out the repo can build your app!
tsconfig.json
TypeScript编译器的配置,你的IDE会借助它来给你提供更好的帮助。
TypeScript compiler configuration for your IDE to pick up and give you helpful tooling.