fix: 翻译完 deployment
This commit is contained in:
parent
55613601c2
commit
d5c6f7ca1b
@ -1,92 +1,204 @@
|
||||
# Deployment
|
||||
|
||||
# 部署
|
||||
|
||||
|
||||
To deploy your application, you have to compile it, and then host the JavaScript, CSS, and HTML on a web server. Built Angular applications are very portable and can live in any environment or served by any technology, such as Node, Java, .NET, PHP, and many others.
|
||||
|
||||
要部署应用,你必须先编译它,然后在 Web 服务器上托管 JavaScript、CSS 和 HTML。构建后的 Angular 应用程序非常容易移植,它可以在任何环境中运行,也可以用任何技术提供服务,比如 Node,Java,.NET,PHP 等等。
|
||||
|
||||
|
||||
<div class="alert is-helpful">
|
||||
|
||||
|
||||
Whether you came here directly from [Your First App](getting-started "Getting Started: Your First App"), or completed the entire online store application through the [Routing](getting-started/routing "Getting Started: Routing"), [Managing Data](getting-started/data "Getting Started: Managing Data"), and [Forms](getting-started/forms "Getting Started: Forms") sections, you have an application that you can deploy by following the instructions in this section.
|
||||
|
||||
无论你是从[你的第一个应用](getting-started "入门:你的第一个应用")直接来到这里,还是经过[路由](getting-started/routing "入门:路由")、[管理数据](getting-started/data "入门:管理数据")和[表单](getting-started/forms "入门:表单")部分,完成了整个在线商店应用之后来到这里,都可以按照本节中的说明进行部署。
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
## Deploying from StackBlitz
|
||||
|
||||
## 从 StackBlitz 开始部署
|
||||
|
||||
|
||||
StackBlitz allows you to publish your Angular app directly to Firebase from your project. The steps below outline how to deploy it quickly without setting up your own hosting environment.
|
||||
|
||||
StackBlitz 允许你从项目中把 Angular 应用直接发布到 Firebase。下面的步骤简要描述了如何在不必设置自己的开发环境的情况下快速部署它。
|
||||
|
||||
|
||||
1. In your StackBlitz project, in the left menu bar, click the `Firebase` icon.
|
||||
|
||||
在 StackBlitz 项目的左侧菜单栏中,点击 `Firebase` 图标。
|
||||
|
||||
1. If you don’t have a `Firebase` account, visit the [Firebase](https://firebase.google.com/ "Firebase web site") to sign up for a free hosting account.
|
||||
|
||||
如果你还没有 `Firebase` 帐户,请访问 [Firebase](https://firebase.google.com/ "Firebase 网站") 注册一个免费的托管帐户。
|
||||
|
||||
1. Click the `Sign into Google` button and follow the prompts to give `StackBlitz` access your `Firebase` projects
|
||||
|
||||
点击 `Sign into Google` 按钮,然后按照提示允许 `StackBlitz` 访问你的 `Firebase` 项目
|
||||
|
||||
1. Select the `project` where you wish to deploy your application.
|
||||
|
||||
选择要部署应用的项目(`project`)。
|
||||
|
||||
1. Click the `Deploy` button to deploy your application.
|
||||
|
||||
单击 `Deploy` 按钮,部署应用。
|
||||
|
||||
1. After the deployment completes, click the `Open live site` link to view your app live.
|
||||
|
||||
部署完成后,点击 `Open live site` 链接,立即查看你的应用。
|
||||
|
||||
|
||||
## Building locally
|
||||
|
||||
## 本地构建
|
||||
|
||||
|
||||
To build your application locally, you will need to download the source code from your StackBlitz project. Click the `Download Project` icon in the left menu across from `Project` to download your files.
|
||||
|
||||
要在本地构建应用,你需要从 StackBlitz 项目中下载源代码。单击左侧菜单中的 `Download Project` 图标以下载文件。
|
||||
|
||||
|
||||
Once you have the source code downloaded and unzipped, use the [Angular Console](https://angularconsole.com "Angular Console web site") to serve the application, or you install Node and have the Angular CLI installed.
|
||||
|
||||
下载并解压源代码后,就可以使用 [Angular Console](https://angularconsole.com "Angular Console 的网站") 来启动开发服务器了,也可以先安装 Node 再安装 Angular CLI。
|
||||
|
||||
|
||||
From the terminal, install the Angular CLI globally with:
|
||||
|
||||
在终端上,全局安装 Angular CLI:
|
||||
|
||||
|
||||
```sh
|
||||
npm install -g @angular/cli
|
||||
```
|
||||
|
||||
This will install the command `ng` into your system, which is the command you use to create new workspaces, new projects, serve your application during development, or produce builds that can be shared or distributed.
|
||||
|
||||
这会把命令 `ng` 安装到你的系统中,你可以用它的命令来创建新工作区或新项目、启动开发服务器、或构建那些可以共享或分发的版本。
|
||||
|
||||
|
||||
Create a new Angular CLI workspace using the [`ng new`](cli/new "CLI ng new command reference") command:
|
||||
|
||||
[`ng new`](cli/new "在 CLI 中输入新的命令参考") 命令用来创建一个新的 Angular CLI 工作空间:
|
||||
|
||||
|
||||
```sh
|
||||
ng new my-project-name
|
||||
```
|
||||
|
||||
From there you replace the `/src` folder with the one from your `StackBlitz` download, and then perform a build.
|
||||
|
||||
进入你从 `StackBlitz` 下载的 `/src` 文件夹,然后执行 build 命令。
|
||||
|
||||
|
||||
```sh
|
||||
ng build --prod
|
||||
```
|
||||
|
||||
This will produce the files that you need to deploy.
|
||||
|
||||
这会产生你要部署的文件。
|
||||
|
||||
|
||||
#### Hosting the built project
|
||||
|
||||
#### 托管已构建的项目
|
||||
|
||||
|
||||
The files in the `dist/my-project-name` folder are static and can be hosted on any web server capable of serving files (node, Java, .NET) or any backend (Firebase, Google Cloud, App Engine, others).
|
||||
|
||||
`dist/my-project-name` 文件夹中的文件都是静态的,可以托管在任何能够提供文件服务的 Web 服务器上(node,Java,.NET),也可以是任何后端(Firebase,Google Cloud,App Engine 等)。
|
||||
|
||||
|
||||
### Hosting an Angular app on Firebase
|
||||
|
||||
### 在 Firebase 上托管一个 Angular 应用
|
||||
|
||||
|
||||
One of the easiest ways to get your site live is to host it using Firebase.
|
||||
|
||||
要想让你的网站上线,最简单的办法之一就是使用 Firebase 托管它。
|
||||
|
||||
|
||||
1. Sign up for a firebase account on [Firebase](https://firebase.google.com/ "Firebase web site").
|
||||
|
||||
在 [Firebase](https://firebase.google.com/ "Firebase 网站") 上注册一个 firebase 账号。
|
||||
|
||||
1. Create a new project, giving it any name you like.
|
||||
|
||||
创建一个新项目,给它任意名字。
|
||||
|
||||
1. Install the `firebase-tools` CLI that will handle your deployment using `npm install -g firebase-tools`.
|
||||
|
||||
使用 `npm install -g firebase-tools` 安装 `firebase-tools` CLI 来处理你的部署。
|
||||
|
||||
1. Connect your CLI to your Firebase account and initialize the connection to your project using `firebase login` and `firebase init`.
|
||||
|
||||
把你的 CLI 和 Firebase 帐户联系起来,使用 `firebase login` 和 `firebase init` 来初始化这个联系。
|
||||
|
||||
1. Follow the prompts to select the `Firebase` project you creating for hosting.
|
||||
|
||||
按照提示选择你为托管它而创建的 `Firebase` 项目。
|
||||
|
||||
1. Deploy your application with `firebase deploy` because StackBlitz has created a `firebase.json` that tells Firebase how to serve your app.
|
||||
|
||||
用 `firebase deploy` 命令部署你的应用,这是因为 StackBlitz 已经创建好了一个 firebase.json,它会告诉 Firebase 如何用你的应用提供服务。
|
||||
|
||||
1. Once deployed, visit https://your-firebase-project-name.firebaseapp.com to see it live!
|
||||
|
||||
部署之后,访问 <https://your-firebase-project-name.firebaseapp.com> 进行实时查看!
|
||||
|
||||
|
||||
### Hosting an Angular app anywhere else
|
||||
|
||||
### 在其它地方托管 Angular 应用
|
||||
|
||||
|
||||
To host an Angular app on another web host, you'll need to upload or send the files to the host.
|
||||
Because you are building a Single Page Application, you'll also need to make sure you redirect any invalid URLs to your `index.html` file.
|
||||
Learn more about development and distribution of your application in the [Building & Serving](guide/build "Building and Serving Angular Apps") and [Deployment](guide/deployment "Deployment guide") guides.
|
||||
|
||||
要在其它网络主机上托管 Angular 应用,你需要上传文件或把它们发送到那台主机。由于你正在构建一个单页面应用,所以你还要确保把所有无效的 URL 都重定向到 `index.html` 文件。在[构建与服务](guide/build "构建和提供 Angular 应用服务")和[部署](guide/deployment "部署指南")指南”中可以找到关于开发和部署应用的更多信息。
|
||||
|
||||
|
||||
## Join our community
|
||||
|
||||
## 加入我们的社区
|
||||
|
||||
|
||||
You are now an Angular developer! [Share this moment](https://twitter.com/intent/tweet?url=https://next.angular.io/getting-started&text=I%20just%20finished%20the%20Angular%20Getting%20Started%20Tutorial "Angular on Twitter"), tell us what you thought of this Getting Started, or submit [suggestions for future editions](https://github.com/angular/angular/issues/new/choose "Angular GitHub repository new issue form").
|
||||
|
||||
你现在是一位 Angular 的开发者了,告诉我们你对这份“入门文档”的看法,或者[为今后的版本](https://github.com/angular/angular/issues/new/choose "Angular GitHub 存储库中的新问题表单")提交[建议](https://github.com/angular/angular/issues/new/choose "Angular GitHub 存储库中的新问题表单")。
|
||||
|
||||
|
||||
Angular offers many more capabilities, and you now have a foundation that empowers you to build an application and explore those other capabilities:
|
||||
|
||||
Angular 还提供了更多功能,不过你现在已经有了基础,可以让你构建一个应用并探索其它的能力:
|
||||
|
||||
|
||||
* Angular provides advanced capabilities for mobile apps, animation, internationalization, server-side rendering, and more.
|
||||
|
||||
Angular 为移动应用、动画、国际化、服务器端渲染等提供了先进的功能。
|
||||
|
||||
* [Angular Material](https://material.angular.io/ "Angular Material web site") offers an extensive library of Material Design components.
|
||||
|
||||
[Angular Material](https://material.angular.io/ "Angular Material 网站") 提供了丰富的 Material Design 组件库。
|
||||
|
||||
* [Angular Protractor](https://protractor.angular.io/ "Angular Protractor web site") offers an end-to-end testing framework for Angular apps.
|
||||
|
||||
[Angular Protractor](https://protractor.angular.io/ "Angular Protractor 网站") 为 Angular 应用提供了一个端到端的测试框架。
|
||||
|
||||
* Angular also has an extensive [network of 3rd-party tools and libraries](https://angular.io/resources "Angular resources list").
|
||||
|
||||
Angular 还拥有广泛的[第三方工具和库](https://angular.io/resources "Angular 资源列表")互助网。
|
||||
|
||||
|
||||
Keep current by following the [Angular blog](https://blog.angular.io/ "Angular blog").
|
||||
|
||||
|
||||
敬请关注 [Angular 官方博客](https://blog.angular.io/ "Angular 的博客")。
|
||||
|
||||
|
||||
|
@ -41,7 +41,7 @@ You'll find many resources to complement the Angular docs. Mozilla's MDN docs in
|
||||
StackBlitz creates a starter Angular app.
|
||||
We've seeded this particular app with a top bar—containing the store name and checkout icon—and the title for a product list.
|
||||
|
||||
用 StackBlitz 创建一个入门级 Angular 应用。我们已经为这个应用添加了一个包含商店名称和结帐图标的顶栏,以及产品列表的标题。
|
||||
用 StackBlitz 创建一个入门级 Angular 应用。我们已经为这个应用添加了一个包含商店名称和结帐图标的顶栏,以及商品列表的标题。
|
||||
|
||||
|
||||
<!--
|
||||
@ -89,27 +89,27 @@ This section introduces five things you can do in an Angular template to affect
|
||||
Angular's template syntax extends HTML and JavaScript.
|
||||
In this section, you'll learn about template syntax by enhancing the "Products" area.
|
||||
|
||||
Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通过增强 “产品” 区域来了解模板语法。
|
||||
Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通过增强 “商品” 区域来了解模板语法。
|
||||
|
||||
|
||||
(So that you can focus on the template syntax, the following steps use predefined product data and methods from the `product-list.component.ts` file.)
|
||||
|
||||
(为了让你专注于模板语法,下列步骤使用了 `product-list.component.ts` 文件中预定义的一些产品数据和方法。)
|
||||
(为了让你专注于模板语法,下列步骤使用了 `product-list.component.ts` 文件中预定义的一些商品数据和方法。)
|
||||
|
||||
|
||||
1. In the `product-list` folder, open the template file `product-list.component.html`.
|
||||
|
||||
在 `product-list` 文件夹中,打开模板文件 `product-list.component.html` 。
|
||||
在 `product-list` 文件夹中,打开模板文件 `product-list.component.html`。
|
||||
|
||||
|
||||
1. Modify the product list template to display a list of product names.
|
||||
|
||||
修改产品列表模板,看是否列出了产品名称。
|
||||
修改商品列表模板,看是否列出了商品名称。
|
||||
|
||||
|
||||
1. We want each product in the list to be displayed the same way, one after the other on the page. To iterate over the predefined list of products, use the `*ngFor` directive. Put the `*ngFor` directive on a `<div>`, as shown below:
|
||||
|
||||
我们希望列表中的每个产品能以同样的方式在页面上挨个显示出来。要遍历这些预定义的产品列表,请使用 `*ngFor` 指令。把 `*ngFor` 指令加到 `<div>` 上,如下图所示:
|
||||
我们希望列表中的每个商品能以同样的方式在页面上挨个显示出来。要遍历这些预定义的商品列表,请使用 `*ngFor` 指令。把 `*ngFor` 指令加到 `<div>` 上,如下图所示:
|
||||
|
||||
|
||||
<code-example header="src/app/product-list/product-list.component.html" path="getting-started/src/app/product-list/product-list.component.2.html" region="ngfor">
|
||||
@ -117,7 +117,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
`*ngFor` causes the `<div>` to be repeated for each product in the list.
|
||||
|
||||
`*ngFor` 会导致 `<div>` 被列表中的每个产品都重复渲染一次。
|
||||
`*ngFor` 会导致 `<div>` 被列表中的每个商品都重复渲染一次。
|
||||
|
||||
<div class="alert is-helpful">
|
||||
`*ngFor` is a "structural directive". Structural directives shape or reshape the DOM's structure, typically by adding, removing, and manipulating the elements to which they are attached. Any directive with an * is a structural directive.
|
||||
@ -128,7 +128,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
1. To display the names of the products, use the interpolation syntax {{ }}. Interpolation renders a property's value as text. Inside the `<div>`, add an `<h3>` heading to display the interpolation of the product's name property:
|
||||
|
||||
要显示产品的名称,请使用插值语法 `{{}}`。插值会把属性的值作为文本渲染出来。在 `<div>` 里面,添加一个 `<h3>` 标题来显示产品 name 属性的插值:
|
||||
要显示商品的名称,请使用插值语法 `{{}}`。插值会把属性的值作为文本渲染出来。在 `<div>` 里面,添加一个 `<h3>` 标题来显示商品 name 属性的插值:
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-list/product-list.component.2.html" region="interpolation">
|
||||
@ -136,7 +136,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
The preview pane immediately updates to display the name of each product in the list.
|
||||
|
||||
预览窗格会立即更新,以显示列表中每个产品的名称。
|
||||
预览窗格会立即更新,以显示列表中每个商品的名称。
|
||||
|
||||
|
||||
<figure>
|
||||
@ -145,7 +145,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
1. In the final app, each product name will be a link to product details. Add the anchor now, and set the anchor's title to be the product's name by using the property binding [ ] syntax, as shown below:
|
||||
|
||||
在最终的应用中,每个产品名称都会链接到产品详情。现在添加这个链接,并使用属性绑定语法 `[]` 把该链接的 title 设置成该产品的名字,如下所示:
|
||||
在最终的应用中,每个商品名称都会链接到商品详情。现在添加这个链接,并使用属性绑定语法 `[]` 把该链接的 title 设置成该商品的名字,如下所示:
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-list/product-list.component.2.html">
|
||||
@ -157,7 +157,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
In the preview pane, hover over the displayed product name to see the bound name property value. They are the same. Interpolation {{ }} lets you render the property value as text; property binding [ ] lets you use the property value in a template expression.
|
||||
|
||||
在预览窗格中,将鼠标悬停在显示的产品名称上,可以看到绑定的 name 属性值。它们俩是一样的。 插值表达式 `{{}}` 允许你把属性值渲染为文本;而属性绑定语法 `[]` 则允许你在模板表达式中使用属性值。
|
||||
在预览窗格中,将鼠标悬停在显示的商品名称上,可以看到绑定的 name 属性值。它们俩是一样的。插值表达式 `{{}}` 允许你把属性值渲染为文本;而属性绑定语法 `[]` 则允许你在模板表达式中使用属性值。
|
||||
|
||||
|
||||
<figure>
|
||||
@ -167,7 +167,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
1. Add the product descriptions. On the paragraph tag, use an `*ngIf` directive so that the paragraph element is only created if the current product has a description.
|
||||
|
||||
添加产品说明。在 p 标签上,使用 `*ngIf` 指令,这样才能在当前产品有描述信息的情况下创建这个 p 元素。
|
||||
添加商品说明。在 p 标签上,使用 `*ngIf` 指令,这样才能在当前商品有描述信息的情况下创建这个 p 元素。
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-list/product-list.component.3.html">
|
||||
@ -175,7 +175,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
The app now displays the name and description of each product in the list, as shown below. Notice that the final product does not have a description paragraph at all. Because the product's description property is empty, the paragraph element—including the word "Description"—is not created.
|
||||
|
||||
该应用会立即在列表中显示每种产品的名称和描述,如下所示。请注意,最后一个产品根本没有描述信息。由于该产品的 description 属性为空,因此不会创建 p 元素(包括静态文本 “Description”)。
|
||||
该应用会立即在列表中显示每种商品的名称和描述,如下所示。请注意,最后一个商品根本没有描述信息。由于该商品的 description 属性为空,因此不会创建 p 元素(包括静态文本 “Description”)。
|
||||
|
||||
|
||||
<figure>
|
||||
@ -184,7 +184,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
1. Add a button so users can share a product with friends. Bind the button's `click` event to the `share()` event that we defined for you (in `product-list.component.ts`). Event binding is done by using ( ) around the event, as shown below:
|
||||
|
||||
添加一个按钮,以便让用户可与朋友分享产品。把 button 的 `click` 事件绑定到我们替你定义好的 `share()` 事件上(位于 `product-list.component.ts` )。事件绑定是通过把事件名称包裹在圆括号 `()` 中完成的,如下所示:
|
||||
添加一个按钮,以便让用户可与朋友分享商品。把 button 的 `click` 事件绑定到我们替你定义好的 `share()` 事件上(位于 `product-list.component.ts` )。事件绑定是通过把事件名称包裹在圆括号 `()` 中完成的,如下所示:
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-list/product-list.component.4.html">
|
||||
@ -192,7 +192,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
|
||||
Each product now has a "Share" button:
|
||||
|
||||
现在,每个产品都有一个 “Share” 按钮了:
|
||||
现在,每个商品都有一个 “Share” 按钮了:
|
||||
|
||||
|
||||
<figure>
|
||||
@ -211,7 +211,7 @@ Angular 的模板语法扩展了 HTML 和 JavaScript。在本节中,你将通
|
||||
The app now has a product list and sharing feature.
|
||||
In the process, you've learned to use five common features of Angular's template syntax:
|
||||
|
||||
该应用现在具有产品列表和共享功能。在这个过程中,你已经学会了 Angular 模板语法的五个常用特性:
|
||||
该应用现在具有商品列表和共享功能。在这个过程中,你已经学会了 Angular 模板语法的五个常用特性:
|
||||
|
||||
|
||||
* `*ngFor`
|
||||
@ -233,7 +233,7 @@ In the process, you've learned to use five common features of Angular's template
|
||||
|
||||
Learn more: See the [Template Syntax guide](guide/template-syntax "Template Syntax") for information about the full capabilities of Angular's template syntax.
|
||||
|
||||
要了解关于 Angular 模板语法全部特性的信息,请参阅[模板语法指南](guide/template-syntax "模板语法") 。
|
||||
要了解关于 Angular 模板语法全部特性的信息,请参阅[模板语法指南](guide/template-syntax "模板语法")。
|
||||
|
||||
|
||||
</div>
|
||||
@ -248,7 +248,7 @@ Learn more: See the [Template Syntax guide](guide/template-syntax "Template Synt
|
||||
*Components* define areas of responsibility in your UI that let you reuse these sets of UI functionality.
|
||||
You've already built one with the product list component.
|
||||
|
||||
*组件*在 UI 中定义了一些责任区,让你能重用这些 UI 功能集。你已经通过产品列表组件构建了一个。
|
||||
*组件*在 UI 中定义了一些责任区,让你能重用这些 UI 功能集。你已经通过商品列表组件构建了一个。
|
||||
|
||||
|
||||
A component is comprised of three things:
|
||||
@ -258,15 +258,15 @@ A component is comprised of three things:
|
||||
|
||||
* **A component class,** which handles data and functionality. In the previous section, the product data and the `share()` method were defined for you in the component class.
|
||||
|
||||
**一个组件类**,它用来处理数据和功能。上一节,我们在组件类中定义了产品数据和 `share()` 方法。
|
||||
**一个组件类**,它用来处理数据和功能。上一节,我们在组件类中定义了商品数据和 `share()` 方法。
|
||||
|
||||
* **An HTML template,** which determines what is presented to the user. In the previous section, you modified the product list's HTML template to display the name, description, and a "Share" button for each product.
|
||||
|
||||
**一个 HTML 模板**,它决定了用户的呈现方式。在上一节中,你修改了产品列表的 HTML 模板,以显示每个产品的名称、描述和 “Share” 按钮。
|
||||
**一个 HTML 模板**,它决定了用户的呈现方式。在上一节中,你修改了商品列表的 HTML 模板,以显示每个商品的名称、描述和 “Share” 按钮。
|
||||
|
||||
* **Component-specific styles** that define the look and feel. The product list does not define any styles.
|
||||
|
||||
**组件专属的样式**定义了外观和感觉。产品列表中还没有定义任何样式。
|
||||
**组件专属的样式**定义了外观和感觉。商品列表中还没有定义任何样式。
|
||||
|
||||
|
||||
<!--
|
||||
@ -311,19 +311,19 @@ Currently, our app has three components:
|
||||
|
||||
* `app-product-list` (purple box) is the product list that you modified in the previous section.
|
||||
|
||||
`app-product-list`(紫色框)是你在上一节中修改过的产品列表。
|
||||
`app-product-list`(紫色框)是你在上一节中修改过的商品列表。
|
||||
|
||||
|
||||
In the next section, you'll expand the app's capabilities by adding a new component for a product alert. You'll add it as a child of the product list component.
|
||||
|
||||
在下一节中,你将通过为产品提醒添加新组件来扩展应用的功能。你可以把它添加为产品列表组件的子组件。
|
||||
在下一节中,你将通过为商品提醒添加新组件来扩展应用的功能。你可以把它添加为商品列表组件的子组件。
|
||||
|
||||
|
||||
<div class="alert is-helpful">
|
||||
|
||||
Learn more: See [Introduction to Components](guide/architecture-components "Architecture > Introduction to Components") for more information about components and how they interact with templates.
|
||||
|
||||
要了解关于组件及其与模板交互的更多信息,请参阅[“组件简介”](guide/architecture-components "架构>组件简介") 。
|
||||
要了解关于组件及其与模板交互的更多信息,请参阅[“组件简介”](guide/architecture-components "架构>组件简介")。
|
||||
|
||||
|
||||
</div>
|
||||
@ -339,17 +339,17 @@ Learn more: See [Introduction to Components](guide/architecture-components "Arch
|
||||
Currently, the product list displays the name and description of each product.
|
||||
You might have noticed that the product list component also defines a `products` property that contains imported data for each product. (See the `products` array in `products.ts`.)
|
||||
|
||||
目前,产品列表会显示每个产品的名称和描述。你可能已经注意到,产品列表组件还定义了一个 `products` 属性,它包含每个产品的导入数据。(参见 `products.ts` 中的 `products` 数组。)
|
||||
目前,商品列表会显示每个商品的名称和描述。你可能已经注意到,商品列表组件还定义了一个 `products` 属性,它包含每个商品的导入数据。(参见 `products.ts` 中的 `products` 数组。)
|
||||
|
||||
|
||||
We're going to create a new alert feature. The alert feature will take a product as an input. It will then check the product's price, and, if the price is greater than $700, it will display a "Notify Me" button that lets users sign up for notifications when the product goes on sale.
|
||||
|
||||
我们要创建一个新的提醒功能。提醒功能会接收一个产品作为输入。然后它会检查产品的价格,如果价格高于 700 美元,它会显示一个“Notify Me”(通知我)按钮,让用户注册一个当产品上市时发送的通知。
|
||||
我们要创建一个新的提醒功能。提醒功能会接收一个商品作为输入。然后它会检查商品的价格,如果价格高于 700 美元,它会显示一个“Notify Me”(通知我)按钮,让用户注册一个当商品上市时发送的通知。
|
||||
|
||||
|
||||
1. Create a new product alerts component.
|
||||
|
||||
创建一个新产品提醒组件。
|
||||
创建一个新商品提醒组件。
|
||||
|
||||
|
||||
1. Right click on the `app` folder and use the `Angular Generator` to generate a new component named `product-alerts`.
|
||||
@ -399,19 +399,19 @@ We're going to create a new alert feature. The alert feature will take a product
|
||||
|
||||
1. Set up the new product alerts component to receive a product as input:
|
||||
|
||||
设置新产品提醒组件,让它接收一个产品作为输入:
|
||||
设置新商品提醒组件,让它接收一个商品作为输入:
|
||||
|
||||
|
||||
1. Import `Input` from `@angular/core`.
|
||||
|
||||
从 `@angular/core` 导入 `Input` 。
|
||||
从 `@angular/core` 导入 `Input`。
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-alerts/product-alerts.component.1.ts" region="imports"></code-example>
|
||||
|
||||
1. In the `ProductAlertsComponent` class definition, define a property named `product` with an `@Input` decorator. The `@Input` decorator indicates that the property value will be passed in from the component's parent (in this case, the product list component).
|
||||
|
||||
在 `ProductAlertsComponent` 类的定义中,定义一个带 `@Input` 装饰器的 `product` 属性。`@Input` 装饰器指出其属性值是从组件的父组件(在本例中就是产品列表组件)中传入的。
|
||||
在 `ProductAlertsComponent` 类的定义中,定义一个带 `@Input` 装饰器的 `product` 属性。`@Input` 装饰器指出其属性值是从组件的父组件(在本例中就是商品列表组件)中传入的。
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-alerts/product-alerts.component.1.ts" region="input-decorator"></code-example>
|
||||
@ -421,19 +421,19 @@ We're going to create a new alert feature. The alert feature will take a product
|
||||
|
||||
1. Define the view for the new product alert component.
|
||||
|
||||
定义这个新产品提醒组件的视图。
|
||||
定义这个新商品提醒组件的视图。
|
||||
|
||||
|
||||
Open the `product-alerts.component.html` template and replace the placeholder paragraph with a "Notify Me" button that appears if the product price is over $700.
|
||||
|
||||
打开 `product-alerts.component.html` 模板,把作为占位符的 p 替换为如果产品价格超过 700 美元就要显示出来的“通知我”按钮。
|
||||
打开 `product-alerts.component.html` 模板,把作为占位符的 p 替换为如果商品价格超过 700 美元就要显示出来的“通知我”按钮。
|
||||
|
||||
|
||||
<code-example header="src/app/product-alerts/product-alerts.component.html" path="getting-started/src/app/product-alerts/product-alerts.component.1.html"></code-example>
|
||||
|
||||
1. Display the new product alert component as part of (a child of) the product list.
|
||||
|
||||
把这个新产品提醒组件显示为该产品列表的一部分(子组件)。
|
||||
把这个新商品提醒组件显示为该商品列表的一部分(子组件)。
|
||||
|
||||
|
||||
1. Open `product-list.component.html`.
|
||||
@ -448,14 +448,14 @@ We're going to create a new alert feature. The alert feature will take a product
|
||||
|
||||
1. Pass the current product as input to the component using property binding.
|
||||
|
||||
通过属性绑定把当前产品作为输入传递给组件。
|
||||
通过属性绑定把当前商品作为输入传递给组件。
|
||||
|
||||
|
||||
<code-example header="src/app/product-list/product-list.component.html" path="getting-started/src/app/product-list/product-list.component.5.html" region="app-product-alerts"></code-example>
|
||||
|
||||
The new product alert component takes a product as input from the product list. With that input, it shows or hides the "Notify Me" button, based on the price of the product. The Phone XL price is over $700, so the "Notify Me" button appears on that product.
|
||||
|
||||
新产品提醒组件会从产品列表中获取产品作为输入信息。通过该输入,它会根据产品的价格显示或隐藏 “Notify Me” 按钮。由于 Phone XL 的售价超过了 700 美元,所以该产品上会出现“Notify Me”按钮。
|
||||
新商品提醒组件会从商品列表中获取商品作为输入信息。通过该输入,它会根据商品的价格显示或隐藏 “Notify Me” 按钮。由于 Phone XL 的售价超过了 700 美元,所以该商品上会出现“Notify Me”按钮。
|
||||
|
||||
|
||||
<figure>
|
||||
@ -481,7 +481,7 @@ Learn more: See [Component Interaction](guide/component-interaction "Components
|
||||
|
||||
The "Notify Me" button doesn't do anything yet. In this section, you'll set up the product alert component so that it emits an event up to the product list component when the user clicks "Notify Me". You'll define the notification behavior in the product list component.
|
||||
|
||||
“Notify Me” 按钮暂时还没有任何操作。在本节中,你将设置产品提醒组件,以便当用户单击“Notify Me”时,它会向该产品列表组件发出事件。你将在产品列表组件中定义通知行为。
|
||||
“Notify Me” 按钮暂时还没有任何操作。在本节中,你将设置商品提醒组件,以便当用户单击“Notify Me”时,它会向该商品列表组件发出事件。你将在商品列表组件中定义通知行为。
|
||||
|
||||
|
||||
1. Open `product-alerts.component.ts`.
|
||||
@ -501,7 +501,7 @@ The "Notify Me" button doesn't do anything yet. In this section, you'll set up t
|
||||
|
||||
1. In the component class, define a property named `notify` with an `@Output` decorator and an instance of event emitter. This makes it possible for the product alert component to emit an event when the value of the notify property changes.
|
||||
|
||||
在组件类中,用 `@Output` 装饰器和一个事件发射器(EventEmitter)实例定义一个名为 `notify` 的属性。这可以让产品提醒组件在 notify 属性发生变化时发出事件。
|
||||
在组件类中,用 `@Output` 装饰器和一个事件发射器(EventEmitter)实例定义一个名为 `notify` 的属性。这可以让商品提醒组件在 notify 属性发生变化时发出事件。
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-alerts/product-alerts.component.ts" region="input-output"></code-example>
|
||||
@ -511,7 +511,7 @@ The "Notify Me" button doesn't do anything yet. In this section, you'll set up t
|
||||
|
||||
1. In the product alert template (`product-alerts.component.html`), update the "Notify Me" button with an event binding to call the `notify.emit()` method.
|
||||
|
||||
在产品提醒模板(`product-alerts.component.html`)中,用事件绑定更新“Notify Me”按钮,以调用 `notify.emit()` 方法。
|
||||
在商品提醒模板(`product-alerts.component.html`)中,用事件绑定更新“Notify Me”按钮,以调用 `notify.emit()` 方法。
|
||||
|
||||
|
||||
<code-example header="src/app/product-alerts/product-alerts.component.html" path="getting-started/src/app/product-alerts/product-alerts.component.html"></code-example>
|
||||
@ -521,7 +521,7 @@ The "Notify Me" button doesn't do anything yet. In this section, you'll set up t
|
||||
|
||||
1. Next, define the behavior that should happen when the button is clicked. Recall that it's the parent (product list component)—not the product alerts component—that's going to take the action. In the `product-list.component.ts` file, define an `onNotify()` method, similar to the `share()` method:
|
||||
|
||||
接下来,定义单击该按钮时应该发生的行为。回想一下,应该由父组件(产品列表组件)采取行动,而不是产品提醒组件。在 `product-list.component.ts` 文件中,定义一个 `onNotify()` 方法,类似于 `share()` 方法:
|
||||
接下来,定义单击该按钮时应该发生的行为。回想一下,应该由父组件(商品列表组件)采取行动,而不是商品提醒组件。在 `product-list.component.ts` 文件中,定义一个 `onNotify()` 方法,类似于 `share()` 方法:
|
||||
|
||||
|
||||
<code-example header="src/app/product-list/product-list.component.ts" path="getting-started/src/app/product-list/product-list.component.ts" region="on-notify"></code-example>
|
||||
@ -531,12 +531,12 @@ The "Notify Me" button doesn't do anything yet. In this section, you'll set up t
|
||||
|
||||
1. Finally, update the product list component to receive output from the product alerts component.
|
||||
|
||||
最后,修改产品列表组件以接收产品提醒组件的输出。
|
||||
最后,修改商品列表组件以接收商品提醒组件的输出。
|
||||
|
||||
|
||||
In `product-list.component.html`, bind the `app-product-alerts` component (which is what displays the "Notify Me" button) to the `onNotify()` method of the product list component.
|
||||
|
||||
在 `product-list.component.html` 中,把 `app-product-alerts` 组件(就是它显示的“Notify Me”按钮)的 `notify` 事件绑定到产品列表组件的 `onNotify()` 方法。
|
||||
在 `product-list.component.html` 中,把 `app-product-alerts` 组件(就是它显示的“Notify Me”按钮)的 `notify` 事件绑定到商品列表组件的 `onNotify()` 方法。
|
||||
|
||||
|
||||
<code-example header="src/app/product-list/product-list.component.html" path="getting-started/src/app/product-list/product-list.component.6.html" region="on-notify"></code-example>
|
||||
@ -578,7 +578,7 @@ You have a basic online store catalog, with a product list, "Share" button, and
|
||||
You've learned about the foundation of Angular: components and template syntax.
|
||||
You've also learned how the component class and template interact, and how components communicate with each other.
|
||||
|
||||
你有了一个基本的在线商店目录,它带有产品列表,“Share”按钮和“Notify Me”按钮。你已经了解了 Angular 的基础知识:组件和模板语法。你还学习了组件类和模板如何交互,以及组件如何相互通信。
|
||||
你有了一个基本的在线商店目录,它带有商品列表,“Share”按钮和“Notify Me”按钮。你已经了解了 Angular 的基础知识:组件和模板语法。你还学习了组件类和模板如何交互,以及组件如何相互通信。
|
||||
|
||||
|
||||
To continue exploring Angular, choose either of the following options:
|
||||
@ -588,9 +588,9 @@ To continue exploring Angular, choose either of the following options:
|
||||
|
||||
* [Continue to the "Routing" section](getting-started/routing "Getting Started: Routing") to create a product details page that can be accessed by clicking a product name and that has its own URL pattern.
|
||||
|
||||
[继续浏览“路由”部分](getting-started/routing "入门:路由") ,创建一个产品详情页面,通过单击产品名称,可以访问该页面,该页面有自己的 URL 模式。
|
||||
[继续浏览“路由”部分](getting-started/routing "入门:路由"),创建一个商品详情页面,通过单击商品名称,可以访问该页面,该页面有自己的 URL 模式。
|
||||
|
||||
* [Skip ahead to the "Deployment" section](getting-started/deployment "Getting Started: Deployment") to deploy your app to Firebase or move to local development.
|
||||
|
||||
[跳到“部署”部分](getting-started/deployment "入门:部署"),把你的应用部署到 Firebase 或转为本地开发。
|
||||
[跳到“部署”部分](getting-started/deployment "入门:部署"),把你的应用部署到 Firebase 或转成本地开发。
|
||||
|
||||
|
@ -7,12 +7,12 @@ At the end of [Your First App](getting-started "Getting Started: Your First App"
|
||||
The app doesn't have any variable states or navigation.
|
||||
There is one URL, and that URL always displays the "My Store" page with a list of products and their descriptions.
|
||||
|
||||
在[你的第一个应用](getting-started "入门:你的第一个应用")结束时,这个在线商店应用会有一个基本的产品名录。该应用还没有任何可变的状态或导航。它只有一个 URL,该 URL 总是会显示“我的商店”页面,其中是产品列表及其描述。
|
||||
在[你的第一个应用](getting-started "入门:你的第一个应用")结束时,这个在线商店应用会有一个基本的商品名录。该应用还没有任何可变的状态或导航。它只有一个 URL,该 URL 总是会显示“我的商店”页面,其中是商品列表及其描述。
|
||||
|
||||
|
||||
In this section, you'll extend the app to display full product details in separate pages, with their own URLs.
|
||||
|
||||
在本节中,你将扩展本应用以便在单独的页面中显示完整的产品详情,并让它使用自己的 URL。
|
||||
在本节中,你将扩展本应用以便在单独的页面中显示完整的商品详情,并让它使用自己的 URL。
|
||||
|
||||
|
||||
To do this, you'll use the Angular *router*.
|
||||
@ -42,12 +42,12 @@ The router enables navigation from one view to the next as users perform applica
|
||||
|
||||
The app is already set up to use the Angular router and to use routing to navigate to the product list component you modified earlier. Let's define a route to show individual product details.
|
||||
|
||||
该应用已经设置为使用 Angular 路由器,并通过路由导航到之前修改过的产品列表组件。让我们来定义一个可以显示产品详情的路由。
|
||||
该应用已经设置为使用 Angular 路由器,并通过路由导航到之前修改过的商品列表组件。让我们来定义一个可以显示商品详情的路由。
|
||||
|
||||
|
||||
1. Generate a new component for product details. Give the component the name `product-details`.
|
||||
|
||||
为产品详情生成一个新组件。把组件命名为 `product-details`。
|
||||
为商品详情生成一个新组件。把组件命名为 `product-details`。
|
||||
|
||||
|
||||
Reminder: In the file list, right-click the `app` folder, choose `Angular Generator` and `Component`.
|
||||
@ -57,7 +57,7 @@ The app is already set up to use the Angular router and to use routing to naviga
|
||||
|
||||
1. In `app.module.ts`, add a route for product details, with a `path` of `products/:productId` and `ProductDetailsComponent` for the `component`.
|
||||
|
||||
在 `app.module.ts` 中,添加一个产品详情路由,该路由的 `path` 是 `products/:productId`,`component` 是 `ProductDetailsComponent`。
|
||||
在 `app.module.ts` 中,添加一个商品详情路由,该路由的 `path` 是 `products/:productId`,`component` 是 `ProductDetailsComponent`。
|
||||
|
||||
|
||||
<code-example header="src/app/app.module.ts" path="getting-started/src/app/app.module.ts" region="product-details-route">
|
||||
@ -76,7 +76,7 @@ The app is already set up to use the Angular router and to use routing to naviga
|
||||
|
||||
We want the user to click a product name to display the details for that product.
|
||||
|
||||
我们希望用户点击产品名称来显示该产品的详情。
|
||||
我们希望用户点击商品名称来显示该商品的详情。
|
||||
|
||||
|
||||
1. Open `product-list.component.html`.
|
||||
@ -91,7 +91,7 @@ The app is already set up to use the Angular router and to use routing to naviga
|
||||
|
||||
1. Modify the product name anchor to include a `routerLink`.
|
||||
|
||||
修改产品名称的链接,使其包含 `routerLink`。
|
||||
修改商品名称的链接,使其包含 `routerLink`。
|
||||
|
||||
|
||||
<code-example header="src/app/product-list/product-list.component.html" path="getting-started/src/app/product-list/product-list.component.html" region="router-link">
|
||||
@ -103,12 +103,12 @@ The app is already set up to use the Angular router and to use routing to naviga
|
||||
|
||||
The RouterLink directive gives the router control over the anchor element. In this case, the route (URL) contains one fixed segment (`/products`) and the final segment is variable, inserting the id property of the current product. For example, the URL for a product with an `id` of 1 will be similar to `https://getting-started-myfork.stackblitz.io/products/1`.
|
||||
|
||||
RouterLink 指令让路由器控制了一个链接元素。在这种情况下,路由(URL)包含一个固定的区段( `/products` ),但其最后一个区段是变量,要插入当前产品的 id 属性。例如,`id` 为 1 的产品的 URL 类似于 `https://getting-started-myfork.stackblitz.io/products/1`。
|
||||
RouterLink 指令让路由器控制了一个链接元素。在这种情况下,路由(URL)包含一个固定的区段( `/products` ),但其最后一个区段是变量,要插入当前商品的 id 属性。例如,`id` 为 1 的商品的 URL 类似于 `https://getting-started-myfork.stackblitz.io/products/1`。
|
||||
|
||||
|
||||
1. Test the router by clicking a product name. The app displays the product details component, which currently always says "product-details works!" (We'll fix this in the next section.)
|
||||
|
||||
通过单击产品名称来测试路由器。该应用会显示产品详情组件,该组件目前始终显示 “product-details works!” (我们将在下一节修复此问题。)
|
||||
通过单击商品名称来测试路由器。该应用会显示商品详情组件,该组件目前始终显示 “product-details works!” (我们将在下一节修复此问题。)
|
||||
|
||||
|
||||
Notice that the URL in the preview window changes. The final segment is `products/1`.
|
||||
@ -127,7 +127,7 @@ The app is already set up to use the Angular router and to use routing to naviga
|
||||
|
||||
The product details component handles the display of each product. The Angular Router displays components based on the browser's URL and your defined routes. You'll use the Angular Router to combine the `products` data and route information to display the specific details for each product.
|
||||
|
||||
产品详情组件负责处理每个产品的显示。Angular 的路由器会根据浏览器的 URL 和你定义的这些路由来决定如何显示组件。你可以通过 Angular 的路由器来组合使用 `products` 数据和路由信息,以显示每个产品的详情。
|
||||
商品详情组件负责处理每个商品的显示。Angular 的路由器会根据浏览器的 URL 和你定义的这些路由来决定如何显示组件。你可以通过 Angular 的路由器来组合使用 `products` 数据和路由信息,以显示每个商品的详情。
|
||||
|
||||
|
||||
1. Open `product-details.component.ts`
|
||||
@ -137,12 +137,12 @@ The product details component handles the display of each product. The Angular R
|
||||
|
||||
1. Arrange to use product data from an external file.
|
||||
|
||||
改用外部文件中的产品数据。
|
||||
改用外部文件中的商品数据。
|
||||
|
||||
|
||||
1. Import `ActivatedRoute` from the `@angular/router` package, and the `products` array from `../products`.
|
||||
|
||||
从 `@angular/router` 包导入 `ActivatedRoute` ,从 `../products` 文件导入 `products` 数组。
|
||||
从 `@angular/router` 包导入 `ActivatedRoute`,从 `../products` 文件导入 `products` 数组。
|
||||
|
||||
|
||||
<code-example header="src/app/product-details/product-details.component.ts" path="getting-started/src/app/product-details/product-details.component.1.ts" region="imports">
|
||||
@ -168,7 +168,7 @@ The product details component handles the display of each product. The Angular R
|
||||
|
||||
1. In the `ngOnInit()` method, *subscribe* to route params and fetch the product based on the `productId`.
|
||||
|
||||
在 `ngOnInit()` 方法中, *订阅(subscribe)*路由参数并根据其 `productId` 获取产品信息。
|
||||
在 `ngOnInit()` 方法中,*订阅(subscribe)*路由参数并根据其 `productId` 获取商品信息。
|
||||
|
||||
|
||||
<code-example path="getting-started/src/app/product-details/product-details.component.1.ts" region="get-product">
|
||||
@ -177,12 +177,12 @@ The product details component handles the display of each product. The Angular R
|
||||
The route parameters correspond to the path variables defined in the route. The `productId` is provided from
|
||||
the URL that was matched to the route. You use the `productId` to display the details for each unique product.
|
||||
|
||||
这个路由参数对应于路由中定义的路径变量。`productId` 是从与该路由匹配的 URL 中提供的。你可以通过 `productId` 来显示每个单独产品的详细信息。
|
||||
这个路由参数对应于路由中定义的路径变量。`productId` 是从与该路由匹配的 URL 中提供的。你可以通过 `productId` 来显示每个单独商品的详细信息。
|
||||
|
||||
|
||||
1. Update the template to display product details information inside an `*ngIf`.
|
||||
|
||||
修改模板,在 `*ngIf` 中显示产品详情。
|
||||
修改模板,在 `*ngIf` 中显示商品详情。
|
||||
|
||||
|
||||
<code-example header="src/app/product-details/product-details.component.html" path="getting-started/src/app/product-details/product-details.component.html" region="details">
|
||||
@ -190,7 +190,7 @@ The product details component handles the display of each product. The Angular R
|
||||
|
||||
Now, when the user clicks on a name in the product list, the router navigates you to the distinct URL for the product, swaps out the product list component for the product details component, and displays the product details.
|
||||
|
||||
现在,当用户点击产品列表中的某个名字时,路由器就会导航到产品的不同网址,用产品详情组件代替产品列表组件,并显示产品详情。
|
||||
现在,当用户点击商品列表中的某个名字时,路由器就会导航到商品的不同网址,用商品详情组件代替商品列表组件,并显示商品详情。
|
||||
|
||||
|
||||
<figure>
|
||||
@ -218,11 +218,11 @@ Congratulations! You have integrated routing into your online store.
|
||||
|
||||
* Products are linked from the product list page to individual products
|
||||
|
||||
从产品列表页面链接到了单个产品
|
||||
从商品列表页面链接到了单个商品
|
||||
|
||||
* Users can click on a product name from the list to see details in a new view, with a distinct URL (route)
|
||||
|
||||
用户可以点击列表中的某个产品名称来在新视图中查看其详细信息,并带有独特的 URL(路由)
|
||||
用户可以点击列表中的某个商品名称来在新视图中查看其详细信息,并带有显著的 URL(路由)
|
||||
|
||||
|
||||
To continue exploring Angular, choose either of the following options:
|
||||
@ -232,7 +232,7 @@ To continue exploring Angular, choose either of the following options:
|
||||
|
||||
* [Continue to the "Managing Data" section](getting-started/data "Getting Started: Managing Data") to add the shopping cart feature, using a service to manage the cart data and using HTTP to retrieve external data for shipping prices.
|
||||
|
||||
[继续浏览“管理数据”部分](getting-started/data "入门:管理数据") ,以添加购物车功能,使用服务来管理购物车数据,并通过 HTTP 检索出货价格的外部数据。
|
||||
[继续浏览“管理数据”部分](getting-started/data "入门:管理数据"),以添加购物车功能,使用服务来管理购物车数据,并通过 HTTP 检索配送价格的外部数据。
|
||||
|
||||
* [Skip ahead to the Deployment section](getting-started/deployment "Getting Started: Deployment") to deploy your app to Firebase or move to local development.
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user