2017-02-14 11:34:05 -08:00
|
|
|
/**
|
|
|
|
* @license
|
|
|
|
* Copyright Google Inc. All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
|
|
* found in the LICENSE file at https://angular.io/license
|
|
|
|
*/
|
|
|
|
|
2019-08-22 19:16:25 -07:00
|
|
|
import {DOCUMENT, ɵgetDOM as getDOM} from '@angular/common';
|
2019-03-11 19:20:40 -05:00
|
|
|
import {Inject, Injectable, Optional} from '@angular/core';
|
2019-08-22 19:16:25 -07:00
|
|
|
import {ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID} from '@angular/platform-browser';
|
2017-02-14 11:34:05 -08:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ServerStylesHost extends SharedStylesHost {
|
2017-02-22 16:06:21 -08:00
|
|
|
private head: any = null;
|
2017-02-14 11:34:05 -08:00
|
|
|
|
2017-02-22 16:06:21 -08:00
|
|
|
constructor(
|
|
|
|
@Inject(DOCUMENT) private doc: any,
|
|
|
|
@Optional() @Inject(ɵTRANSITION_ID) private transitionId: string) {
|
|
|
|
super();
|
2019-08-30 12:52:48 -07:00
|
|
|
this.head = doc.getElementsByTagName('head')[0];
|
2017-02-22 16:06:21 -08:00
|
|
|
}
|
2017-02-14 11:34:05 -08:00
|
|
|
|
|
|
|
private _addStyle(style: string): void {
|
2017-08-08 02:17:40 -07:00
|
|
|
let adapter = getDOM();
|
2017-02-14 11:34:05 -08:00
|
|
|
const el = adapter.createElement('style');
|
2019-08-29 21:24:33 -07:00
|
|
|
el.textContent = style;
|
2017-02-22 16:06:21 -08:00
|
|
|
if (!!this.transitionId) {
|
2019-08-30 12:52:48 -07:00
|
|
|
el.setAttribute('ng-transition', this.transitionId);
|
2017-02-14 11:34:05 -08:00
|
|
|
}
|
2019-08-30 12:52:48 -07:00
|
|
|
this.head.appendChild(el);
|
2017-02-14 11:34:05 -08:00
|
|
|
}
|
|
|
|
|
2017-02-22 16:06:21 -08:00
|
|
|
onStylesAdded(additions: Set<string>) { additions.forEach(style => this._addStyle(style)); }
|
2017-02-14 11:34:05 -08:00
|
|
|
}
|