6.0.6 • Published 3 months ago

@acpaas-ui/ngx-context v6.0.6

Weekly downloads
21
License
-
Repository
-
Last release
3 months ago

@acpaas-ui/ngx-context

This package manages meta tags and other SEO properties.

Usage

import { ContextModule, ContextService } from '@acpaas-ui/ngx-context';

Documentation

Visit our documentation site for full how-to docs and guidelines

Different ways to set tags and other SEO properties.

Set defaults

You can set defaults and other options for the module by using the forRoot() option in the import section:

API

NameDefault valueDescription
useTitleSuffix: boolean;falseAdd an optional title suffix.
extendTitle: boolean;falseAppend parent page titles (when using router context).
titleDelimiter: string;'|'The separator to use when extendTitle is true.
defaults: Context;{}Default values for the meta tags. Have a look at the list down below for an overview of possible tags.
routerContext: boolean;trueListen for meta data on the route changes.

Example

@NgModule({
    imports: [
        ContextModule.forRoot({
            useTitleSuffix: true,
            extendTitle: true,
            titleDelimiter: ' | ',
            defaults: {
                titleSuffix: 'Context Module',
            },
            routerContext: true,
        }),
    ]
})
Set tags on routes

You can set tags on routes using the data property. The ContextService will subscribe to the router and pick up these tags automatically.

export const CONTEXT_EXAMPLES_ROUTES: Routes = [
    {
        path: '',
        component: ContextDemoPageComponent,
        pathMatch: 'full',
        data: {
            meta: {
                page: 'Context example page',
                title: 'Context',
                description: 'Description of the context example page',
                metatags: 'Antwerp UI, Angular, context',
            },
        },
    },
];
Set tags on routes

You can set tags manually in your components using the loadContext method as well. This is useful for async data or generic routes.

import { ContextService } from '@acpaas-ui/ngx-context';

@Component({
    providers: [
        ContextService,
    ],
})

export class ContextDemoPageComponent {
    constructor(private contextService: ContextService) {}

    public setTitle() {
        this.contextService.updateContext({
            title: 'New context example title',
        });
    }
}
<button class="a-button" (click)="setTitle()">Set title</button>

Default available tags

The most used tags are available in the Context interface. You are however, free to use whichever tag you need in the format [key: string]: string;.

  • title
  • titleSuffix
  • description
  • favIcon
  • og:url
  • og:type
  • og:title
  • og:description
  • og:image
  • fb:app_id
  • og:locale
  • og:locale:alternate
  • og:see_also
  • og:updated_time
  • twitter:card
  • twitter:site
  • twitter:creator

Contributing

Visit our Contribution Guidelines for more information on how to contribute.

6.0.6

3 months ago

6.0.5

3 months ago

6.0.3

8 months ago

6.0.2

8 months ago

6.0.4

7 months ago

6.0.0

10 months ago

6.0.0-beta.0

12 months ago

7.0.0-beta.1

12 months ago

5.0.0

3 years ago

4.6.1

3 years ago

4.6.0

3 years ago

4.0.0

4 years ago

4.0.0-rc.10

4 years ago

4.0.0-rc.2

4 years ago

4.0.0-rc.7

4 years ago

4.0.0-rc.6

4 years ago

4.0.0-rc.9

4 years ago

4.0.0-rc.8

4 years ago

4.0.0-rc.1

4 years ago