2017-02-22 16:06:21 -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
|
|
|
|
*/
|
|
|
|
|
2017-05-16 15:14:55 -07:00
|
|
|
import {APP_INITIALIZER, ApplicationInitStatus, Inject, InjectionToken, Injector, Provider} from '@angular/core';
|
2017-02-22 16:06:21 -08:00
|
|
|
|
|
|
|
import {getDOM} from '../dom/dom_adapter';
|
|
|
|
import {DOCUMENT} from '../dom/dom_tokens';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An id that identifies a particular application being bootstrapped, that should
|
|
|
|
* match across the client/server boundary.
|
|
|
|
*/
|
|
|
|
export const TRANSITION_ID = new InjectionToken('TRANSITION_ID');
|
|
|
|
|
2017-05-16 15:14:55 -07:00
|
|
|
export function appInitializerFactory(transitionId: string, document: any, injector: Injector) {
|
|
|
|
return () => {
|
|
|
|
// Wait for all application initializers to be completed before removing the styles set by
|
|
|
|
// the server.
|
|
|
|
injector.get(ApplicationInitStatus).donePromise.then(() => {
|
|
|
|
const dom = getDOM();
|
|
|
|
const styles: any[] =
|
|
|
|
Array.prototype.slice.apply(dom.querySelectorAll(document, `style[ng-transition]`));
|
|
|
|
styles.filter(el => dom.getAttribute(el, 'ng-transition') === transitionId)
|
|
|
|
.forEach(el => dom.remove(el));
|
|
|
|
});
|
2017-02-22 16:06:21 -08:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export const SERVER_TRANSITION_PROVIDERS: Provider[] = [
|
|
|
|
{
|
|
|
|
provide: APP_INITIALIZER,
|
2017-05-16 15:14:55 -07:00
|
|
|
useFactory: appInitializerFactory,
|
|
|
|
deps: [TRANSITION_ID, DOCUMENT, Injector],
|
2017-02-22 16:06:21 -08:00
|
|
|
multi: true
|
|
|
|
},
|
|
|
|
];
|