Skip to content

API Reference

Home > @davidlj95/ngx-meta

ngx-meta package

Classes

Class Description
NgxMetaCoreModule

Provides ngx-meta's core library services.

Check out provideNgxMetaCore() for the standalone, recommended API.

Use NgxMetaCoreModule.forRoot() method. Importing the module class alone does nothing.

NgxMetaElementsService Manages <meta> elements inside <head>
NgxMetaJsonLdModule

Provides JSON-LD module metadata managers.

Check out provideNgxMetaJsonLd() for the standalone, recommended API.

NgxMetaMetadataLoaderModule

Allows to load metadata managers after library has been initialized.

Check out provideNgxMetaMetadataLoader() for the standalone, recommended API.

NgxMetaMetaService

Creates, updates or removes <meta> elements.

Uses Angular Meta APIs under the hood.

NgxMetaOpenGraphModule

Provides Open Graph module basic and optional metadata managers.

Check out provideNgxMetaOpenGraph() for the standalone, recommended API.

NgxMetaOpenGraphProfileModule

Provides Open Graph module profile metadata managers.

Check out provideNgxMetaOpenGraphProfile() for the standalone, recommended API.

NgxMetaRoutingModule

Enables managing metadata of a page by specifying it in its Angular Route#data

Use NgxMetaRoutingModule.forRoot() method. Importing the module class alone does nothing.

Check out provideNgxMetaRouting() for the standalone, recommended API.

NgxMetaService Manages the metadata values of the current page.
NgxMetaStandardModule

Provides standard module metadata managers.

Check out provideNgxMetaStandard() for the standalone, recommended API.

NgxMetaTwitterCardModule

Provides Twitter Cards module metadata managers.

Check out provideNgxMetaTwitterCard() for the standalone, recommended API.

Abstract Classes

Abstract Class Description
NgxMetaMetadataManager

Abstract class every metadata manager must implement.

Used as injection token to provide metadata managers the library will take into account.

Functions

Function Description
makeComposedKeyValMetaDefinition(names, options)

Creates a key / value meta definition (NgxMetaMetaDefinition) where the key name is composed by several strings joined by a separator.

See also makeKeyValMetaDefinition()

makeKeyValMetaDefinition(keyName, options) Creates a NgxMetaMetaDefinition for its use with NgxMetaMetaService by understanding <meta> elements as key / value pair elements.
makeMetadataManagerProviderFromSetterFactory(setterFactory, opts)

Creates an Angular factory provider providing an NgxMetaMetadataManager.

See manage custom metadata guide for an example.

provideNgxMetaCore(features) Provides ngx-meta's core library services.
provideNgxMetaJsonLd() Provides JSON-LD module metadata managers.
provideNgxMetaManager(jsonPath, setterFactory, options)

Creates an NgxMetaMetadataManager provider to manage some metadata.

Check out manage your custom metadata guide to learn how to provide your custom metadata managers.

provideNgxMetaMetadataLoader() Allows to load metadata managers after library has been initialized.
provideNgxMetaOpenGraph() Provides Open Graph module basic and optional metadata managers.
provideNgxMetaOpenGraphProfile() Provides Open Graph module profile metadata managers
provideNgxMetaRouting() Enables managing metadata of a page by specifying it in its Angular Route#data
provideNgxMetaStandard() Provides standard module metadata managers.
provideNgxMetaTwitterCard() Provides Twitter Cards module metadata managers.
withManagerDeps(deps)

Specifies dependencies to inject to the setter factory function passed to provideNgxMetaManager()

See also:

- Factory providers' deps

- FactoryProvider#deps

withManagerGlobal(global) Sets the global key to use for a metadata manager created with provideNgxMetaManager()
withManagerObjectMerging()

Enables object merging for the manager being created with provideNgxMetaManager()

See MetadataResolverOptions.objectMerge for more information.

withNameAttribute(value)

Creates an attribute name/value identifying a <meta name="{value}"> element kind.

See NgxMetaElementsService.set().

withNgxMetaBaseUrl(baseUrl)

Provides a base URL to enable resolving relative URLs. Including relative URLs provided by Angular's router.

Metadata values requiring absolute URLs may accept relative URLs then. Internally, the library will turn the relative URL into an absolute URL using the base URL as prefix.

The special value ANGULAR_ROUTER_URL can be used to query the Angular's router URL to be used as relative URL. Which with the feature enabled will be resolved into an absolute URL. Do not use the value if the feature isn't enabled. Otherwise, an invalid URL may end up used as metadata value.

withNgxMetaDefaults(defaults)

Sets up default metadata values.

When setting metadata values for a page, default values will be used as fallback when a metadata value isn't specified.

withOptions(options)

Helper function to combine multiple options (objects).

In case of specifying same options more than once, the latter one will take precedence. Provide them sorted by ascendant priority. Less priority options first. Top priority options last.

Can be used to combine options for:

- provideNgxMetaManager()

withPropertyAttribute(value)

Creates an attribute name/value identifying a <meta property="{value}"> element kind.

See NgxMetaElementsService.set().

Interfaces

Interface Description
GlobalMetadata Specifies metadata that will be used by more than one module.
GlobalMetadataImage

Specifies image metadata (will be used for link previews / social cards) to be used for more than one module. Like:

- OpenGraph.image (needs standard module)

- TwitterCard.image (needs Twitter Cards module)

Open Graph allows for more attributes for the image. Specify OpenGraph.image if you want to customize those too.

JsonLdMetadata Utility type to provide specific JSON-LD module metadata
MakeComposedKeyValMetaDefinitionOptions Options argument object for makeComposedKeyValMetaDefinition()
MakeKeyValMetaDefinitionOptions Options argument object for makeKeyValMetaDefinition()
MakeMetadataManagerProviderFromSetterFactoryOptions Options argument object for makeMetadataManagerProviderFromSetterFactory().
MetadataResolverOptions

Options to resolve metadata values for a metadata manager

Used in NgxMetaMetadataManager.resolverOptions with type MetadataResolverOptions

NgxMetaCoreModuleForRootOptions Configuration options for NgxMetaCoreModule.forRoot()
NgxMetaMetaDefinition

Models a <meta> element which NgxMetaMetaService.set() can manage

To create one, you may also use one of these utility functions:

- makeKeyValMetaDefinition()

- makeComposedKeyValMetaDefinition()

NgxMetaRouteData

Utility type to ensure metadata values are set properly inside an Angular `Route.data`

You can also provide specific metadata module types to ensure type safety of the metadata values. Open doc details to see an example.

OpenGraph Open Graph module metadata values that can be set.
OpenGraphImage See OpenGraph.image
OpenGraphMetadata Utility type to provide specific Open Graph module metadata.
OpenGraphProfile

Open Graph profile metadata for this page.

Requires Open Graph profile metadata managers to work

Standard Standard module metadata values that can be set.
StandardMetadata Utility type to provide specific standard module metadata.
StandardThemeColorMetadataObject See Standard.themeColor
TwitterCard Twitter Cards module metadata values that can be set.
TwitterCardCreatorId See TwitterCardCreator
TwitterCardCreatorUsername See TwitterCardCreator
TwitterCardImage

Image for the card.

Equivalent to OpenGraph.image. This one can be omitted if equivalent is set.

Can be set with GlobalMetadata.image.

Used in TwitterCard.image with type TwitterCardImage

TwitterCardMetadata Utility type to provide specific Twitter Cards module metadata
TwitterCardSiteId See TwitterCardSite
TwitterCardSiteUsername See TwitterCardSite

Variables

Variable Description
ANGULAR_ROUTER_URL

Indicate Angular's router URL shall be used to set the page's URL as a metadata value.

Needs URL resolution feature enabled for the feature to work

A type alias exists to avoid using typeof around AngularRouterUrl

JSON_LD_METADATA_PROVIDER Manages the JsonLdMetadata.jsonLd metadata
OPEN_GRAPH_DESCRIPTION_METADATA_PROVIDER Manages the OpenGraph.description metadata
OPEN_GRAPH_IMAGE_METADATA_PROVIDER Manages the OpenGraph.image metadata
OPEN_GRAPH_LOCALE_METADATA_PROVIDER Manages the OpenGraph.locale metadata
OPEN_GRAPH_PROFILE_FIRST_NAME_METADATA_PROVIDER Manages the OpenGraphProfile.firstName metadata
OPEN_GRAPH_PROFILE_GENDER_FEMALE See OpenGraphProfileGender
OPEN_GRAPH_PROFILE_GENDER_MALE See OpenGraphProfileGender
OPEN_GRAPH_PROFILE_GENDER_METADATA_PROVIDER Manages the OpenGraphProfile.gender metadata
OPEN_GRAPH_PROFILE_LAST_NAME_METADATA_PROVIDER Manages the OpenGraphProfile.lastName metadata
OPEN_GRAPH_PROFILE_USERNAME_METADATA_PROVIDER Manages the OpenGraphProfile.username metadata
OPEN_GRAPH_SITE_NAME_METADATA_PROVIDER Manages the OpenGraph.siteName metadata
OPEN_GRAPH_TITLE_METADATA_PROVIDER Manages the OpenGraph.title metadata
OPEN_GRAPH_TYPE_ARTICLE See OpenGraphType
OPEN_GRAPH_TYPE_BOOK See OpenGraphType
OPEN_GRAPH_TYPE_METADATA_PROVIDER Manages the OpenGraph.type metadata
OPEN_GRAPH_TYPE_MUSIC_ALBUM See OpenGraphType
OPEN_GRAPH_TYPE_MUSIC_PLAYLIST See OpenGraphType
OPEN_GRAPH_TYPE_MUSIC_RADIO_STATION See OpenGraphType
OPEN_GRAPH_TYPE_MUSIC_SONG See OpenGraphType
OPEN_GRAPH_TYPE_PROFILE See OpenGraphType
OPEN_GRAPH_TYPE_VIDEO_EPISODE See OpenGraphType
OPEN_GRAPH_TYPE_VIDEO_MOVIE See OpenGraphType
OPEN_GRAPH_TYPE_VIDEO_OTHER See OpenGraphType
OPEN_GRAPH_TYPE_VIDEO_TV_SHOW See OpenGraphType
OPEN_GRAPH_TYPE_WEBSITE See OpenGraphType
OPEN_GRAPH_URL_METADATA_PROVIDER Manages the OpenGraph.url metadata
STANDARD_APPLICATION_NAME_METADATA_PROVIDER Manages the Standard.applicationName metadata
STANDARD_AUTHOR_METADATA_PROVIDER Manages the Standard.author metadata
STANDARD_CANONICAL_URL_METADATA_PROVIDER Manages the Standard.canonicalUrl metadata
STANDARD_DESCRIPTION_METADATA_PROVIDER Manages the Standard.description metadata
STANDARD_GENERATOR_METADATA_PROVIDER Manages the Standard.generator metadata
STANDARD_KEYWORDS_METADATA_PROVIDER Manages the Standard.keywords metadata
STANDARD_LOCALE_METADATA_PROVIDER Manages the Standard.locale metadata
STANDARD_THEME_COLOR_METADATA_PROVIDER Manages the Standard.themeColor metadata
STANDARD_TITLE_METADATA_PROVIDER Manages the Standard.title metadata
TWITTER_CARD_CARD_METADATA_PROVIDER Manages the TwitterCard.card metadata
TWITTER_CARD_CREATOR_METADATA_PROVIDER Manages the TwitterCard.creator metadata
TWITTER_CARD_DESCRIPTION_METADATA_PROVIDER Manages the TwitterCard.description metadata
TWITTER_CARD_IMAGE_METADATA_PROVIDER Manages the TwitterCard.image metadata
TWITTER_CARD_SITE_METADATA_PROVIDER Manages the TwitterCard.site metadata
TWITTER_CARD_TITLE_METADATA_PROVIDER Manages the TwitterCard.title metadata
TWITTER_CARD_TYPE_APP See TwitterCardType
TWITTER_CARD_TYPE_PLAYER See TwitterCardType
TWITTER_CARD_TYPE_SUMMARY_LARGE_IMAGE See TwitterCardType
TWITTER_CARD_TYPE_SUMMARY See TwitterCardType
withContentAttribute

Creates an NgxMetaElementAttributes object specifying the content attribute to the given value. Plus optional extras.

Unless given value is null or undefined. In that case, undefined is returned.

See NgxMetaElementsService.set()

withManagerJsonPath

Transforms a JSON Path specified as an array of keys into a string joined by dots.

Useful to use with provideNgxMetaManager() to avoid repeating same keys around.

Type Aliases

Type Alias Description
AngularRouterUrl Type alias for ANGULAR_ROUTER_URL symbol
BaseUrl Base URL type for withNgxMetaBaseUrl() feature
MetadataSetter See NgxMetaMetadataManager.set
MetadataSetterFactory

Utility type for a factory function that returns a MetadataSetter given some injectable dependencies.

Used as part of makeMetadataManagerProviderFromSetterFactory().

MetadataValues

Metadata values to use for a page.

Broadly speaking, it's just a JSON object.

See the metadata values JSON guide for more information about typing metadata values JSON with stricter types

NgxMetaElementAttributes

Models a <meta> element HTML's attributes as a key / value JSON object.

Almost equivalent to Angular's MetaDefinition

Only difference is http-equiv property. In an Angular's MetaDefinition, httpEquiv would also be accepted. This way there's no need to quote the key property. But without httpEquiv there's no need to map attribute names. So one bit of code less.

NgxMetaElementNameAttribute See NgxMetaElementsService.set()
NgxMetaMetaContent

Content to be set for a specific <meta> element in the page

Can be undefined or null. In that case, the element will be removed.

See NgxMetaMetaService.set()

OpenGraphProfileGender Genders for OpenGraphProfile.gender property
OpenGraphType Types for OpenGraph.type property
StandardThemeColorMetadata See Standard.themeColor
TwitterCardCreator

@username or Twitter ID of the content creator.

Used in TwitterCard.creator with type TwitterCardCreator

TwitterCardSite

@username or Twitter ID of the author of the website.

Either TwitterCardSiteUsername or TwitterCardSiteId is required.

Used in TwitterCard.site with type TwitterCardSite

TwitterCardType Card types for TwitterCard.card property