ProductPromotion
Logo

Angular.JS

made by https://0x3d.site

GitHub - avivharuzi/ngx-seo: Update SEO title and meta tags easily in Angular apps
Update SEO title and meta tags easily in Angular apps - avivharuzi/ngx-seo
Visit Site

GitHub - avivharuzi/ngx-seo: Update SEO title and meta tags easily in Angular apps

GitHub - avivharuzi/ngx-seo: Update SEO title and meta tags easily in Angular apps

ngx-seo

Update SEO title and meta tags easily in Angular apps.

I created this library because other libraries are not fit enough to my requirements.

npm NPM npm bundle size

Environment Support

  • Angular 6+
  • Server-side Rendering

Compatibility

Versions compatibility list:

@avivharuzi/ngx-seo Angular
16.x.x 16.x.x
15.x.x 15.x.x
14.x.x 14.x.x
13.x.x 13.x.x
12.x.x 12.x.x
11.x.x 11.x.x
10.x.x 10.x.x
1.x.x 6.xx - 9.x.x

Installation

npm i @avivharuzi/ngx-seo

OR

yarn install @avivharuzi/ngx-seo

Usage

Import NgxSeoModule

Import NgxSeoModule into AppModule imports.

import { NgxSeoModule } from '@avivharuzi/ngx-seo';

imports: [
  // ...
  NgxSeoModule.forRoot(),
],

Update Title and Meta Tags from Routes Data

Declare SEO data for each route recommended to use NgxSeo interface to prevent problems.

...
import { NgxSeo } from '@avivharuzi/ngx-seo';

...

const SEO_HOME: NgxSeo = {
  title: 'home page',
  meta: {
    description: 'home page description',
  },
};

const SEO_ABOUT: NgxSeo = {
  title: 'about page',
  meta: {
    description: 'about page description',
  },
};

const routes: Routes = [
  { path: '', component: HomeComponent, data: { seo: SEO_HOME } },
  { path: 'about', component: AboutComponent, data: { seo: SEO_ABOUT } },
];

You can also specify custom meta tags by providing array of MetaDefinition.

const SEO_SPECIAL: NgxSeo = {
  meta: {
    customTags: {
      mySpecial: {
        name: 'mySpecial',
        content: 'mySpecial content :P',
      },
    },
  },
};

const routes: Routes = [
  { path: 'special', component: SpecialComponent, data: { seo: SEO_SPECIAL } },
];

Update Title and Meta Tags Dynamically

You can also to use the service NgxSeoService to dynamically update title or meta tags.

...
export class MoiveDetailComponent implements OnInit {
  movie: Movie;

  constructor(
    private movieService: MovieService,
    private ngxSeoService: NgxSeoService,
  ) {}

  ngOnInit(): void {
    this.movieService.getDetails(1).subscribe(movie => {
      this.movie = movie;

      this.ngxSeoService.setSeo({
        title: movie.title,
        meta: {
          description: movie.description,
        },
      });
    });
  }
}

API

NgxSeoModule

NgxSeoModule.forRoot(config: NgxSeoConfig)

...
NgxSeoModule.forRoot({
  changeTitle: (title) => title,
  preserve: false,
  listenToRouteEvents: true,
})
...

NgxSeoService

NgxSeoService.setSeo(seo: NgxSeo): void

Update SEO title and meta tags.

NgxSeoService.setTitle(title: string): void

Update SEO title.

NgxSeoService.setMeta(meta: NgxSeoMeta): void

Update SEO meta tags.

NgxSeoService.setMetaKeywords(metaKeywords: string | string[]): void

Update meta tag keywords.

NgxSeoService.setMetaDescription(metaDescription: string): void

Update meta tag description.

NgxSeoService.setMetaType(metaType: string): void

Update meta tag type.

NgxSeoService.setMetaCard(metaCard: string): void

Update meta tag card.

NgxSeoService.setMetaImage(metaImage: string): void

Update meta tag image.

NgxSeoService.setMetaUrl(metaUrl: string): void

Update meta tag url.

NgxSeoService.setMetaAuthor(metaAuthor: string): void

Update meta tag author.

NgxSeoService.setMetaSiteName(metaSiteName: string): void

Update meta tag site name.

NgxSeoService.setMetaCanonical(metaCanonical: string): void

Update meta tag canonical.

NgxSeoService.setMetaCustomTags(customTags: MetaDefinition[]): void

Update custom meta tags.

NgxSeoService.removeMeta(): void

Will remove all meta tags from HTML document.

License

MIT

More Resources
to explore the angular.

mail [email protected] to add your project or resources here 🔥.

Related Articles
to learn about angular.

FAQ's
to learn more about Angular JS.

mail [email protected] to add more queries here 🔍.

More Sites
to check out once you're finished browsing here.

0x3d
https://www.0x3d.site/
0x3d is designed for aggregating information.
NodeJS
https://nodejs.0x3d.site/
NodeJS Online Directory
Cross Platform
https://cross-platform.0x3d.site/
Cross Platform Online Directory
Open Source
https://open-source.0x3d.site/
Open Source Online Directory
Analytics
https://analytics.0x3d.site/
Analytics Online Directory
JavaScript
https://javascript.0x3d.site/
JavaScript Online Directory
GoLang
https://golang.0x3d.site/
GoLang Online Directory
Python
https://python.0x3d.site/
Python Online Directory
Swift
https://swift.0x3d.site/
Swift Online Directory
Rust
https://rust.0x3d.site/
Rust Online Directory
Scala
https://scala.0x3d.site/
Scala Online Directory
Ruby
https://ruby.0x3d.site/
Ruby Online Directory
Clojure
https://clojure.0x3d.site/
Clojure Online Directory
Elixir
https://elixir.0x3d.site/
Elixir Online Directory
Elm
https://elm.0x3d.site/
Elm Online Directory
Lua
https://lua.0x3d.site/
Lua Online Directory
C Programming
https://c-programming.0x3d.site/
C Programming Online Directory
C++ Programming
https://cpp-programming.0x3d.site/
C++ Programming Online Directory
R Programming
https://r-programming.0x3d.site/
R Programming Online Directory
Perl
https://perl.0x3d.site/
Perl Online Directory
Java
https://java.0x3d.site/
Java Online Directory
Kotlin
https://kotlin.0x3d.site/
Kotlin Online Directory
PHP
https://php.0x3d.site/
PHP Online Directory
React JS
https://react.0x3d.site/
React JS Online Directory
Angular
https://angular.0x3d.site/
Angular JS Online Directory