W3cubDocs

/Angular

@angular/common

package

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 XMLHttpRequest interface exposed by browsers.

@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.

@angular/common/upgrade

Provides tools for upgrading from the $location service provided in AngularJS to Angular's unified location service.

Primary entry point exports

NgModules

CommonModule

Exports all the basic Angular directives and pipes, such as NgIf, NgForOf, DecimalPipe, and so on. Re-exported by BrowserModule, which is included automatically in the root AppModule when you create a new app with the CLI new command.

Classes

BrowserPlatformLocation

PlatformLocation encapsulates all of the direct calls to platform APIs. This class should not be used directly by an application developer. Instead, use Location.

HashLocationStrategy

A LocationStrategy used to configure the Location service to represent its state in the hash fragment of the browser's URL.

Location

A service that applications can use to interact with a browser's URL.

LocationStrategy

Enables the Location service to read route state from the browser's URL. Angular provides two strategies: HashLocationStrategy and PathLocationStrategy.

NgForOfContext
NgIfContext
NgLocaleLocalization

Returns the plural case based on the locale

NgLocalization
PathLocationStrategy

A LocationStrategy used to configure the Location service to represent its state in the path of the browser's URL.

PlatformLocation

This class should not be used directly by an application developer. Instead, use Location.

ViewportScroller

Defines a scroll position manager. Implemented by BrowserViewportScroller.

XhrFactory

A wrapper around the XMLHttpRequest constructor.

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 en-US.

getLocaleCurrencySymbol

Retrieves the symbol used to represent the currency for the main country corresponding to a given locale. For example, '$' for en-US.

getLocaleDateFormat

Retrieves a localized date-value formatting 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 en-US, periods are morning, noon, afternoon, evening, and midnight.

getLocaleFirstDayOfWeek

Retrieves the first day of the week for the given locale.

getLocaleId

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

Returns whether a platform id represents a browser platform.

isPlatformServer

Returns whether a platform id represents a server platform.

isPlatformWorkerApp

Deprecated: This function serves no purpose since the removal of the Webworker platform. It will always return false.

Returns whether a platform id represents a web worker app platform.

isPlatformWorkerUi

Deprecated: This function serves no purpose since the removal of the Webworker platform. It will always return false.

Returns whether a platform id represents a web worker UI platform.

registerLocaleData

Register global data to be used internally by Angular. See the "I18n guide" to know how to import additional locale data.

Structures

DatePipeConfig

An interface that describes the date pipe configuration, which can be provided using the DATE_PIPE_DEFAULT_OPTIONS token.

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 en-US.

ImageLoaderConfig

Config options recognized by the image loader function.

KeyValue

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 onPopState or onHashChange

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 en-US values.

Plural

Plurality cases used for translating plurals to different languages.

PopStateEvent
TranslationWidth

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 en-US locale

Directives

NgClass

Adds and removes CSS classes on an HTML element.

NgComponentOutlet

Instantiates a Component type and inserts its Host View into the current View. NgComponentOutlet provides a declarative approach for dynamic component creation.

NgFor

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.

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

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 then clause, and when false or null, Angular renders the template provided in an optional else clause. The default template for the else clause is blank.

NgOptimizedImage

Directive that improves image loading performance by enforcing best practices.

NgPlural

Adds / removes DOM sub-trees based on a numeric value. Tailored for pluralization.

NgPluralCase

Creates a view that will be added/removed from the parent NgPlural when the given expression matches the plural expression according to CLDR rules.

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 .<unit> suffix (such as 'top.px', 'font-style.em'). The value is an expression to be evaluated. The resulting non-null value, expressed in the given unit, is assigned to the given style property. If the result of evaluation is null, the corresponding style is removed.

NgSwitch

The [ngSwitch] directive on a container specifies an expression to match against. The expressions to match are provided by ngSwitchCase directives on views within the container.

  • Every view that matches is rendered.
  • If there are no matches, a view with the ngSwitchDefault directive is rendered.
  • Elements within the [NgSwitch] statement but outside of any NgSwitchCase or ngSwitchDefault directive are preserved at the location.
NgSwitchCase

Provides a switch case expression to match against an enclosing ngSwitch expression. When the expressions match, the given NgSwitchCase template is rendered. If multiple match expressions match the switch expression value, all of them are displayed.

NgSwitchDefault

Creates a view that is rendered when no NgSwitchCase expressions match the NgSwitch expression. This statement should be the final case in an NgSwitch.

NgTemplateOutlet

Inserts an embedded view from a prepared TemplateRef.

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

Converts a value into its JSON-format representation. Useful for debugging.

KeyValuePipe

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 Array or String containing a subset (slice) of the elements.

TitleCasePipe

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

A predefined DI token for the base href to be used with the PathLocationStrategy. The base href is the URL prefix that should be preserved when generating and recognizing URLs.

DATE_PIPE_DEFAULT_OPTIONS

DI token that allows to provide default configuration for the DatePipe instances in an application. The value is an object which can include the following fields:

  • dateFormat: configures the default date format. If not provided, the DatePipe will use the 'mediumDate' as a value.
  • timezone: configures the default timezone. If not provided, the DatePipe will use the end-user's local system timezone.
DATE_PIPE_DEFAULT_TIMEZONE

Deprecated: use DATE_PIPE_DEFAULT_OPTIONS token to configure DatePipe

Optionally-provided default timezone to use for all instances of DatePipe (such as '+0430'). If the value isn't provided, the DatePipe will use the end-user's local system timezone.

DOCUMENT

A DI Token representing the main rendering context. In a browser and SSR this is the DOM Document. When using SSR, that document is created by Domino.

IMAGE_CONFIG

Injection token that configures the image optimized image functionality.

IMAGE_LOADER

Injection token that configures the image loader function.

ImageConfig

A configuration object for the NgOptimizedImage directive. Contains:

  • breakpoints: An array of integer breakpoints used to generate srcsets for responsive images.
ImageLoader

Represents an image loader function. Image loader functions are used by the NgOptimizedImage directive to produce full image URL based on the image name and its width.

LOCATION_INITIALIZED

Indicates when a location is initialized.

PRECONNECT_CHECK_BLOCKLIST

Injection token to configure which origins should be excluded from the preconnect checks. It can either be a single string or an array of strings to represent a group of origins, for example:

Time

Represents a time value with hours and minutes.

provideCloudflareLoader

Function that generates an ImageLoader for Cloudflare Image Resizing and turns it into an Angular provider. Note: Cloudflare has multiple image products - this provider is specifically for Cloudflare Image Resizing; it will not work with Cloudflare Images or Cloudflare Polish.

provideCloudinaryLoader

Function that generates an ImageLoader for Cloudinary and turns it into an Angular provider.

provideImageKitLoader

Function that generates an ImageLoader for ImageKit and turns it into an Angular provider.

provideImgixLoader

Function that generates an ImageLoader for Imgix and turns it into an Angular provider.

© 2010–2023 Google, Inc.
Licensed under the Creative Commons Attribution License 4.0.
https://angular.io/api/common