@angular/common
Implements fundamental Angular framework functionality, including directives and pipes, location services used in routing, HTTP services, localization support, and so on.
The CommonModule
exports are re-exported by BrowserModule
, which is included automatically in the root AppModule
when you create a new app with the CLI new
command.
入口点
Entry points
主要
Primary
@angular/common | Implements fundamental Angular framework functionality, including directives and pipes, location services used in routing, HTTP services, localization support, and so on. |
次要
Secondary
@angular/common/http | Implements an HTTP client API for Angular apps that relies on the |
@angular/common/http/testing | Supplies a testing module for the Angular HTTP subsystem. |
@angular/common/testing | Supplies infrastructure for testing functionality supplied by |
@angular/common/upgrade | Provides tools for upgrading from the |
主要入口点的导出
Primary entry point exports
NgModules
CommonModule | 导出所有基本的 Angular 指令和管道,例如 Exports all the basic Angular directives and pipes, such as |
类
Classes
HashLocationStrategy | 此 A |
Location | 一个服务,应用可以用它来与浏览器的 URL 互动。 A service that applications can use to interact with a browser's URL. |
LocationStrategy | 使 Enables the |
NgForOfContext | |
NgIfContext | |
NgLocaleLocalization | 根据语言环境返回复数形式 Returns the plural case based on the locale |
NgLocalization | |
PathLocationStrategy | 此 A |
PlatformLocation | 此类不应由应用程序开发人员直接使用。而应使用 This class should not be used directly by an application developer. Instead, use |
ViewportScroller | 定义滚动位置管理器。由 Defines a scroll position manager. Implemented by |
XhrFactory | A wrapper around the |
函数
Functions
formatCurrency | 使用区域设置规则将数字格式化为货币。 Formats a number as currency using locale rules. |
formatDate | 基于区域规则格式化日期。 Formats a date according to locale rules. |
formatNumber | 将数字格式化为文本格式,并根据区域来设置组大小、分隔符和其他参数。 Formats a number as text, with group sizing, separator, and other parameters based on the locale. |
formatPercent | 根据语言环境规则将数字格式化为百分比。 Formats a number as a percentage according to locale rules. |
getCurrencySymbol | 检索给定货币代码的货币符号。 Retrieves the currency symbol for a given currency code. |
getLocaleCurrencyCode | 检索给定语言环境的默认货币代码。 Retrieves the default currency code for the given locale. |
getLocaleCurrencyName | 检索与给定语言环境相对应的主要国家/地区的货币名称。对于 Retrieves the name of the currency for the main country corresponding to a given locale. For example, 'US Dollar' for |
getLocaleCurrencySymbol | 检索用于表示与给定语言环境对应的主要国家/地区的货币的符号。对于 Retrieves the symbol used to represent the currency for the main country corresponding to a given locale. For example, '$' for |
getLocaleDateFormat | 检索本地化的日期-值格式字符串。 Retrieves a localized date-value formating string. |
getLocaleDateTimeFormat | 检索本地化的日期时间格式字符串。 Retrieves a localized date-time formatting string. |
getLocaleDayNames | 使用公历来检索给定语言环境下的星期几。 Retrieves days of the week for the given locale, using the Gregorian calendar. |
getLocaleDayPeriods | 检索给定语言环境的一天时段字符串。 Retrieves day period strings for the given locale. |
getLocaleDirection | 检索指定语言环境的书写方向 Retrieves the writing direction of a specified locale |
getLocaleEraNames | 检索给定语言环境的格里高利历日历。 Retrieves Gregorian-calendar eras for the given locale. |
getLocaleExtraDayPeriodRules | 检索特定于语言环境的规则,该规则用于确定在为一个语言环境中定义了多个时段时要使用的一天时段。 Retrieves locale-specific rules used to determine which day period to use when more than one period is defined for a locale. |
getLocaleExtraDayPeriods | 检索特定于语言环境的一天时段,该时段大致指示如何用不同的语言分解一天。例如,对于 Retrieves locale-specific day periods, which indicate roughly how a day is broken up in different languages. For example, for |
getLocaleFirstDayOfWeek | 检索给定语言环境中一周的第一天。 Retrieves the first day of the week for the given locale. |
getLocaleId | 从当前已加载的语言环境中检索语言环境 ID。加载的语言环境也可能是全球语言环境,而不是区域性语言环境。 Retrieves the locale ID from the currently loaded locale. The loaded locale could be, for example, a global one rather than a regional one. |
getLocaleMonthNames | 使用公历来检索给定语言环境下一年中的月份。 Retrieves months of the year for the given locale, using the Gregorian calendar. |
getLocaleNumberFormat | 检索给定语言环境下的数字格式。 Retrieves a number format for a given locale. |
getLocaleNumberSymbol | 检索本地化的数字符号,该符号可用于替换数字格式的占位符。 Retrieves a localized number symbol that can be used to replace placeholders in number formats. |
getLocalePluralCase | Retrieves the plural function used by ICU expressions to determine the plural case to use for a given locale. |
getLocaleTimeFormat | 检索本地化的时间值格式字符串。 Retrieves a localized time-value formatting string. |
getLocaleWeekEndRange | 在给定语言环境中被视为周末的工作日范围。 Range of week days that are considered the week-end for the given locale. |
getNumberOfCurrencyDigits | 报告给定货币的小数位数。其值取决于该特定货币中分币是否存在。 Reports the number of decimal digits for a given currency. The value depends upon the presence of cents in that particular currency. |
isPlatformBrowser | 返回平台 ID 是否代表浏览器平台。 Returns whether a platform id represents a browser platform. |
isPlatformServer | 返回平台 ID 是否代表服务器平台。 Returns whether a platform id represents a server platform. |
isPlatformWorkerApp | 返回平台 ID 是否代表 Web Worker 应用平台。 Returns whether a platform id represents a web worker app platform. |
isPlatformWorkerUi | 返回平台 ID 是否代表 Web Worker UI 平台。 Returns whether a platform id represents a web worker UI platform. |
registerLocaleData | 注册全局数据以供 Angular 内部使用。请参阅 “I18n 指南”以了解如何导入其他语言环境的数据。 Register global data to be used internally by Angular. See the "I18n guide" to know how to import additional locale data. |
结构
Structures
FormStyle | 字符串的上下文相关翻译形式。通常,独立版本用于单词的主格形式,格式化的版本则用于所有格。 Context-dependant translation forms for strings. Typically the standalone version is for the nominative form of the word, and the format version is used for the genitive case. |
FormatWidth | 可用于日期时间格式的字符串宽度。特定的字符宽度是特定于语言环境的。示例中是给 String widths available for date-time formats. The specific character widths are locale-specific. Examples are given for |
KeyValue | 一个键值对。通常用于表示 Map 或 Object 中的键值对。 A key value pair. Usually used to represent the key value pairs from a Map or Object. |
LocationChangeEvent | 来自 A serializable version of the event from |
LocationChangeListener | |
NumberFormatStyle | 可用来表示数字的格式化样式。 Format styles that can be used to represent numbers. |
NumberSymbol | 可用于替换数字模式中占位符的符号。例如基于 Symbols that can be used to replace placeholders in number patterns. Examples are based on |
Plural | 用于将复数形式转换为不同语言的复数形式。 Plurality cases used for translating plurals to different languages. |
PopStateEvent | |
TranslationWidth | 字符串宽度可用于翻译。特定的字符宽度是特定于语言环境的。这里给出了英语中 “Sunday” 一词的示例。 String widths available for translations. The specific character widths are locale-specific. Examples are given for the word "Sunday" in English. |
WeekDay | 一周中每一天的值(基于 The value for each day of the week, based on the |
指令
Directives
NgClass | 从 HTML 元素上添加和移除 CSS 类。 Adds and removes CSS classes on an HTML element. |
NgComponentOutlet | 实例化单个 Instantiates a single |
NgForOf | 一种结构型指令,为集合中的每个条目渲染一个模板。如果指令放置在一个元素上,该元素就会成为克隆后的模板的父级。 A structural directive that renders a template for each item in a collection. The directive is placed on an element, which becomes the parent of the cloned templates. |
NgIf | 本结构型指令用于根据表达式的值(强转为 boolean)是否为真值,来有条件的包含某个模板。当表达式计算为 true 时,Angular 会渲染 A structural directive that conditionally includes a template based on the value of an expression coerced to Boolean. When the expression evaluates to true, Angular renders the template provided in a |
NgPlural | 根据数字值添加/删除 DOM 子树。为支持复数词量身定制。 Adds / removes DOM sub-trees based on a numeric value. Tailored for pluralization. |
NgPluralCase | 创建一个视图,当给定表达式根据 CLDR 规则与复数表达式匹配时,将在父视图 Creates a view that will be added/removed from the parent |
NgStyle | 一个属性指令,用于更新容器元素的样式。可以通过指定用冒号分隔的键值对来设置一个或多个样式属性。其键是样式名称,带有可选的 An attribute directive that updates styles for the containing HTML element. Sets one or more style properties, specified as colon-separated key-value pairs. The key is a style name, with an optional |
NgSwitch | 容器上的 The |
NgSwitchCase | 提供一个 switch case 表达式来匹配一个封闭的 Provides a switch case expression to match against an enclosing |
NgSwitchDefault | 创建一个当没有任何 Creates a view that is rendered when no |
NgTemplateOutlet | 根据一个提前备好的 Inserts an embedded view from a prepared |
管道
Pipes
AsyncPipe | 从一个异步回执中解出一个值。 Unwraps a value from an asynchronous primitive. |
CurrencyPipe | Transforms a number to a currency string, formatted according to locale rules that determine group sizing and separator, decimal-point character, and other locale-specific configurations. |
DatePipe | 根据区域设置规则格式化日期值。 Formats a date value according to locale rules. |
DecimalPipe | Formats a value according to digit options and locale rules. Locale determines group sizing and separator, decimal point character, and other locale-specific configurations. |
I18nPluralPipe | 将值映射到根据语言环境规则对该值进行复数化的字符串。 Maps a value to a string that pluralizes the value according to locale rules. |
I18nSelectPipe | 通用选择器,用于显示与当前值匹配的字符串。 Generic selector that displays the string that matches the current value. |
JsonPipe | 把一个值转换成 JSON 字符串格式。在调试时很有用。 Converts a value into its JSON-format representation. Useful for debugging. |
KeyValuePipe | 将 Object 或 Map 转换为键值对数组。 Transforms Object or Map into an array of key value pairs. |
LowerCasePipe | 把文本转换成全小写形式。 Transforms text to all lower case. |
PercentPipe | Transforms a number to a percentage string, formatted according to locale rules that determine group sizing and separator, decimal-point character, and other locale-specific configurations. |
SlicePipe | 从一个 Creates a new |
TitleCasePipe | 把文本转换成标题形式。 把每个单词的第一个字母转成大写形式,并把单词的其余部分转成小写形式。 单词之间用任意空白字符进行分隔,比如空格、Tab 或换行符。 Transforms text to title case. Capitalizes the first letter of each word and transforms the rest of the word to lower case. Words are delimited by any whitespace character, such as a space, tab, or line-feed character. |
UpperCasePipe | 把文本转换成全大写形式。 Transforms text to all upper case. |
类型
Types
APP_BASE_HREF | 预定义的 DI 令牌,用于和 A predefined DI token for the base href to be used with the |
DOCUMENT | 表示主要渲染上下文的 DI 令牌。在浏览器中,这是 DOM 文档。 A DI Token representing the main rendering context. In a browser this is the DOM Document. |
LOCATION_INITIALIZED | 指示何时初始化 location。 Indicates when a location is initialized. |
Time | 用小时和分钟表示的时间值。 Represents a time value with hours and minutes. |