Project

General

Profile

« Previous | Next » 

Revision 46415

SEO meta tags & title for each page | footer menu | cookies law message | entity auto complete | change deposit & claims urls to look alike production (participate/*)

View differences:

angular2-meta.ts
6 6
 * found in the LICENSE file at https://angular.io/license
7 7
 */
8 8

  
9
import {Injectable} from '@angular/core';
9
import {Injectable, Inject} from '@angular/core';
10 10
// es6-modules are used here
11 11
import {DomAdapter, getDOM} from '@angular/platform-browser/src/dom/dom_adapter';
12

  
12
import {DOCUMENT} from '@angular/platform-browser';
13 13
/**
14 14
 * Represent meta element.
15 15
 *
......
54 54
@Injectable()
55 55
export class Meta {
56 56
  private _dom: DomAdapter = getDOM();
57

  
57
  constructor( @Inject(DOCUMENT) private _document: any) { }
58 58
  /**
59
   * Sets the title of the page
60
   */
61
  setTitle(title: string) {
62
    this._document.title = title
63
  }
64
  /**
59 65
   * Adds a new meta tag to the dom.
60 66
   *
61 67
   *  ### Example
......
119 125
    return this._prepareMetaElement(tag, meta);
120 126
  }
121 127

  
128
  updateMeta(name, content) {
129
       const head = this._document.head;
130
       let childNodesAsList = this._dom.childNodesAsList(head);
131
       let metaEl = childNodesAsList.find(el => el['attribs'] ?  el['attribs'].name == name : false);
132
       if (metaEl) metaEl['attribs'].content = content;
133
    }
134
    updateProperty(property, content) {
135
         const head = this._document.head;
136
         let childNodesAsList = this._dom.childNodesAsList(head);
137
         let metaEl = childNodesAsList.find(el => el['attribs'] ?  el['attribs'].property == property : false);
138
         if (metaEl) metaEl['attribs'].content = content;
139
      }
140

  
122 141
  /**
123 142
   * Removes meta tag with the given selector from the dom.
124 143
   *
......
168 187
    return el;
169 188
  }
170 189

  
190
  // private _appendMetaElement(meta: HTMLMetaElement): void {
191
  //   const head = this._dom.getElementsByTagName(this._dom.defaultDoc(), 'head')[0];
192
  //   this._dom.appendChild(head, meta);
193
  // }
171 194
  private _appendMetaElement(meta: HTMLMetaElement): void {
172
    const head = this._dom.getElementsByTagName(this._dom.defaultDoc(), 'head')[0];
195
    const head = this._document.head;
173 196
    this._dom.appendChild(head, meta);
174 197
  }
175

  
176 198
  private _removeMetaElement(meta: HTMLMetaElement): void {
177 199
    const head = this._dom.parentElement(meta);
178 200
    this._dom.removeChild(head, meta);

Also available in: Unified diff