Skip to content

Ngx meta.providengxmetamanager

Home > @davidlj95/ngx-meta > provideNgxMetaManager

provideNgxMetaManager() function

Creates an NgxMetaMetadataManager provider to manage some metadata.

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

Signature:

provideNgxMetaManager: <T>(jsonPath: string, setterFactory: MetadataSetterFactory<T>, options?: _ProvideNgxMetaManagerOptions) => FactoryProvider

Parameters

Parameter Type Description
jsonPath string Path to access the metadata value this manager needs given a JSON object containing metadata values. Path is expressed as the keys to use to access the value joined by a "." character. You can use withManagerJsonPath to provide an array of keys instead. For more information, checkout MetadataResolverOptions.jsonPath
setterFactory MetadataSetterFactory<T> Factory function that creates the MetadataSetter function for the manager (which manages the metadata element on the page). You can inject dependencies either using withManagerDeps() option, that will be passed as arguments to the setter factory function. This way is preferred, as takes fewer bytes of your bundle size. However, type safety depends on you. Or use Angular's `inject` function for a more type-safe option.
options _ProvideNgxMetaManagerOptions (Optional) Extra options for the metadata manager provider creation. Use one of the helpers listed in this method's reference docs to supply one or more of them.

Returns:

FactoryProvider

Remarks

Options can be specified using helper functions. withOptions() can be used to combine more than one.

Available option functions:

Example

const CUSTOM_TITLE_PROVIDER = provideNgxMetaManager<string | undefined>(
    'custom.title',
    (metaElementsService: NgxMetaElementsService) => (value) => {
      metaElementsService.set(
        withNameAttribute('custom:title'),
        withContentAttribute(value),
      )
    },
    withOptions(
     withManagerDeps(NgxMetaElementsService),
     withGlobal('title'),
    ),
  )