19.0.1 • Published 7 months ago

ng-meta-helper v19.0.1

Weekly downloads
-
License
-
Repository
github
Last release
7 months ago

Ng-Meta-Helpers

Automatic update of title, description and link of meta tags through a router. The implementation takes place in the comopent's code, so the data can be asynchronous (Observable, Promise)

Install via NPM

npm install --save ng-meta-helper

Import the NgMetaHelperModule to AppModule with RouterModule

import { NgMetaHelperModule } from "ng-meta-helper";

@NgModule({
  declarations: [AppComponent, StaticChild1Component],
  imports: [BrowserModule, RoutingModule.forRoot({...}), NgMetaHelperModule.config()],
  bootstrap: [AppComponent],
})
export class AppModule {}

Use in component, linking to routing. Add the updateTags () method to the component and implements SeoHelper interface

export class ChildComponent implements SeoHelper {
  updateTags() {
    return this.http.get("api/user/info").pipe(
      map((userInfo) => {
        return {
          title: `Hello! This is my site. ${userInfo.name}`,
          meta: {
            name: { description: "best site" },
            property: { "og:title": "best site of the world" },
          },
          link: {
            canonical: `https://mysite.com/user/${userInfo.name}`,
          },
        };
      })
    );
  }
}

SeoHelper interface :

export type SeoTags = {
  title?: string | null;
  meta?: {
    name?: Record<string, string | null>;
    property?: Record<string, string | null>;
  };
  link?: {
    canonical?: string | null;
    prev?: string | null;
    next?: string | null;
  };
};

export interface SeoHelper {
  updateTags(): SeoTags | Promise<SeoTags> | Observable<SeoTags>;
}
19.0.1

7 months ago

19.0.0

7 months ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.0

4 years ago

0.0.5

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago