Skip to content

Implementing a Meta class for getting and changing HTML meta tags #11115

Closed

Description

@flauc

I'm submitting a

[ ] bug report => search github for a similar issue or PR before submitting
[x] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question

I'd like to implement a shortcut for getting and setting HTML meta values (<meta name="description">, `...).

I think that a long with changing the title it's often useful to change meta values as well.

Current behavior

It's currently possible to use the getDOM().query('meta[name=description'])method to grab the element and then use thegetDOM().setAttribute(el, 'content', 'something')` method to change the content. Therefore this implementation would serve only as a shortcut.

Expected/desired behavior

The Meta class would be very similar to the Title Class

It would have a getMeta() and a setMeta() method. Something like this:

    setMeta(metaName: string, contentValue: string): void {
        const el = getDOM().query(`meta[name=${metaName}]`);
        getDOM().setAttribute(el, metaName, contentValue)
    }

    getMeta(metaName: string): HTMLElement {
        return  getDOM().query(`meta[name=${metaName}]`);
    }

And optionally maybe just a method for returning just the content of the meta and not the entire element:

    getContent(metaName: string): string {
        return getDOM().query(`meta[name=${metaName}]`)..getAttribute('content')
    }
  • Angular version: 2.0.0-rc.5
  • Browser: all
  • Language: all

Activity

  1. added
    feature
    on Aug 30, 2016
  2. added
    area: core
    and removed on Sep 7, 2016
  3. added
    area: common
    and removed
    area: core
    on Oct 12, 2016
  4. angular-automatic-lock-bot commented on Sep 10, 2019

    @angular-automatic-lock-bot

    This issue has been automatically locked due to inactivity.
    Please file a new issue if you are encountering a similar or related problem.

    Read more about our automatic conversation locking policy.

    This action has been performed automatically by a bot.

  5. locked and limited conversation to collaborators on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: commonfeaturefreq1: low

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions