11import Component from '@ember/component' ;
2- import { get , computed } from '@ember/object' ;
3- import { getOwner } from '@ember/application' ;
2+ import { inject as service } from '@ember/service' ;
43import layout from '../templates/components/head-layout' ;
54
65export default Component . extend ( {
76 tagName : '' ,
87 layout,
8+ document : service ( '-document' ) ,
99
1010 /**
1111 * If true, this will tear down any existing head on init of this component.
@@ -15,15 +15,20 @@ export default Component.extend({
1515 */
1616 shouldTearDownOnInit : true ,
1717
18- headElement : computed ( function ( ) {
19- let documentService = getOwner ( this ) . lookup ( 'service:-document' ) ;
20- return documentService . head ;
21- } ) ,
18+ /**
19+ * The element to render into. Defaults to <head> in `init`, overridable for our own tests only.
20+ * @private
21+ */
22+ headElement : null ,
2223
2324 init ( ) {
2425 this . _super ( ...arguments ) ;
2526
26- if ( get ( this , 'shouldTearDownOnInit' ) ) {
27+ if ( this . get ( 'headElement' ) === null ) {
28+ this . set ( 'headElement' , this . get ( 'document.head' ) ) ;
29+ }
30+
31+ if ( this . get ( 'shouldTearDownOnInit' ) ) {
2732 this . _tearDownHead ( ) ;
2833 }
2934 } ,
@@ -38,6 +43,7 @@ export default Component.extend({
3843 }
3944
4045 // clear fast booted head (if any)
46+ let document = this . get ( 'document' ) ;
4147 let startMeta = document . querySelector ( 'meta[name="ember-cli-head-start"]' ) ;
4248 let endMeta = document . querySelector ( 'meta[name="ember-cli-head-end"]' ) ;
4349 if ( startMeta && endMeta ) {
0 commit comments