2017-02-14 14:34:05 -05: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
|
|
|
|
*/
|
|
|
|
|
2018-04-23 13:47:27 -04:00
|
|
|
import {Inject, Injectable, Optional} from '@angular/core';
|
2017-08-08 05:17:40 -04:00
|
|
|
import {DOCUMENT, ɵDomAdapter as DomAdapter, ɵSharedStylesHost as SharedStylesHost, ɵTRANSITION_ID, ɵgetDOM as getDOM} from '@angular/platform-browser';
|
2017-02-14 14:34:05 -05:00
|
|
|
|
|
|
|
@Injectable()
|
|
|
|
export class ServerStylesHost extends SharedStylesHost {
|
2017-02-22 19:06:21 -05:00
|
|
|
private head: any = null;
|
2017-02-14 14:34:05 -05:00
|
|
|
|
2017-02-22 19:06:21 -05:00
|
|
|
constructor(
|
|
|
|
@Inject(DOCUMENT) private doc: any,
|
|
|
|
@Optional() @Inject(ɵTRANSITION_ID) private transitionId: string) {
|
|
|
|
super();
|
|
|
|
this.head = getDOM().getElementsByTagName(doc, 'head')[0];
|
|
|
|
}
|
2017-02-14 14:34:05 -05:00
|
|
|
|
|
|
|
private _addStyle(style: string): void {
|
2017-08-08 05:17:40 -04:00
|
|
|
let adapter = getDOM();
|
2017-02-14 14:34:05 -05:00
|
|
|
const el = adapter.createElement('style');
|
|
|
|
adapter.setText(el, style);
|
2017-02-22 19:06:21 -05:00
|
|
|
if (!!this.transitionId) {
|
|
|
|
adapter.setAttribute(el, 'ng-transition', this.transitionId);
|
2017-02-14 14:34:05 -05:00
|
|
|
}
|
2017-02-22 19:06:21 -05:00
|
|
|
adapter.appendChild(this.head, el);
|
2017-02-14 14:34:05 -05:00
|
|
|
}
|
|
|
|
|
2017-02-22 19:06:21 -05:00
|
|
|
onStylesAdded(additions: Set<string>) { additions.forEach(style => this._addStyle(style)); }
|
2017-02-14 14:34:05 -05:00
|
|
|
}
|