填寫這份《一分鐘調查》,幫我們(開發組)做得更好!去填寫Home

範本語法

Template syntax

在 Angular 中,範本就是一塊 HTML。在範本中,你可以透過一種特殊語法來使用 Angular 的許多功能。

In Angular, a template is a chunk of HTML. Within a template, you can use special syntax to leverage many of Angular's features.

先決條件

Prerequisites

在學習範本語法之前,你應該熟悉下列內容:

Before learning template syntax, you should be familiar with the following:


應用程式中的每個 Angular 範本都是一塊 HTML,你可以將其包含在瀏覽器顯示的頁面中。 Angular 中的 HTML 範本與常規 HTML 一樣,可以在瀏覽器中渲染檢視或使用者介面,但功能要多得多。

Each Angular template in your app is a section of HTML that you can include as a part of the page that the browser displays. An Angular HTML template renders a view, or user interface, in the browser, just like regular HTML, but with a lot more functionality.

使用 Angular CLI 產生 Angular 應用時, app.component.html 檔案是一個包含佔位符 HTML 的預設範本。

When you generate an Angular app with the Angular CLI, the app.component.html file is the default template containing placeholder HTML.

本範本語法指南向你展示了如何透過協調類別和範本之間的資料來控制 UX/UI。

The template syntax guides show you how you can control the UX/UI by coordinating data between the class and the template.

大多數範本語法指南都有專門的可工作的範例應用,這些應用程式示範了每個指南中的各個主題。要檢視把所有應用合在一起時的工作情況,請參閱綜合Template Syntax Live Code / 下載範例

Most of the Template Syntax guides have dedicated working example apps that demonstrate the individual topic of each guide. To see all of them working together in one app, see the comprehensiveTemplate Syntax Live Code / 下載範例.

增強你的 HTML

Empower your HTML

透過在範本中使用 Angular 的特有語法,你可以擴充套件應用程式的 HTML 詞彙表。例如,Angular 可以透過內建的範本函式、變數、事件監聽和資料繫結等功能來幫助你動態獲取和設定 DOM(文件物件模型)中的值。

With special Angular syntax in your templates, you can extend the HTML vocabulary of your apps. For example, Angular helps you get and set DOM (Document Object Model) values dynamically with features such as built-in template functions, variables, event listening, and data binding.

幾乎所有的 HTML 語法都是有效的範本語法。但是,由於 Angular 範本只是整個網頁的一部分,而不是整個網頁,因此你不需要包含諸如 <html><body><base> 元素。這樣你可以專注於正在開發的那部分頁面。

Almost all HTML syntax is valid template syntax. However, because an Angular template is part of an overall webpage, and not the entire page, you don't need to include elements such as <html>, <body>, or <base>. You can focus exclusively on the part of the page you are developing.

為了消除指令碼注入攻擊的風險,Angular 不支援範本中使用 <script> 元素。Angular 會忽略 <script> 標記,並向瀏覽器控制檯輸出一條警告。欲知詳情,參閱“安全性”頁面。

To eliminate the risk of script injection attacks, Angular does not support the <script> element in templates. Angular ignores the <script> tag and outputs a warning to the browser console. For more information, see the Security page.

關於範本語法的更多資訊

More on template syntax

你可能也對以下內容感興趣:

You may also be interested in the following: