Is it possible to have HTML titles and meta tags set with an Angular 8 component recognized by...

Discussão em 'Angular' iniciado por Tom Price, Janeiro 29, 2025.

  1. Tom Price

    Tom Price Guest

    My component uses setTitle and updateTag to update the title and tags. Remaining data on the screen is updated via template binding to an object obtained via a host request. Google search console shows the correct screen data but the default title and meta tags.

    Is there a way to address this issue without Universal?

    constructor(private dataService: DataService, private route: ActivatedRoute, private meta: Meta,
    private title: Title, private canonicalService: CanonicalService) {}

    ngOnInit() {
    this.canonicalService.setCanonicalURL();
    this.route.params.subscribe(
    params => {
    const id = +params['id'];
    this.getLicense(id);
    }
    );
    let list = sessionStorage.getItem('liclist');
    if (list) {
    this.licList = JSON.parse(list);
    }
    this.dataService.getEnum().subscribe((data: Enum[]) => {
    this.enums = data;
    });
    }

    getLicense(id) {
    this.dataService.getLicense(id).subscribe((data: License) => {
    this.license = data;
    this.licListPtr = this.licList.findIndex(x => x === id);
    this.meta.updateTag({
    name: "keywords",
    content: !!this.license.keywords ? this.license.keywords.toLowerCase().replace("~", ", ") : ' '
    });
    let desc = this.license.licDesc;
    if (!!this.license.occs) {
    this.license.occs.forEach(o => {
    desc += `\nOccupation ${o.occCode} ${o.occTitle.toLowerCase()}`;
    });
    this.meta.updateTag({
    name: "description",
    content: desc
    });
    this.title.setTitle(`Licensing for ${this.license.licTitle}`);
    }

    })
    }

    Continue reading...

Compartilhe esta Página