npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@avivharuzi/ngx-seo

v16.0.0

Published

Update SEO title and meta tags easily in Angular apps

Downloads

242

Readme

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