@@ -247,7 +247,7 @@ export function main() {
247247
248248 for ( var i = 0 ; i < 20 ; i ++ ) {
249249 dynamicBindings . push ( bind ( i ) . toValue ( i ) ) ;
250- }
250+ }
251251
252252 function createPei ( parent , index , bindings , distance = 1 , hasShadowRoot = false , dirVariableBindings = null ) {
253253 var directiveBinding = ListWrapper . map ( bindings , b => {
@@ -278,7 +278,7 @@ export function main() {
278278 return inj ;
279279 }
280280
281- function parentChildInjectors ( parentBindings , childBindings , parentPreBuildObjects = null ) {
281+ function parentChildInjectors ( parentBindings , childBindings , parentPreBuildObjects = null , imperativelyCreatedInjector = null ) {
282282 if ( isBlank ( parentPreBuildObjects ) ) parentPreBuildObjects = defaultPreBuiltObjects ;
283283
284284 var protoParent = createPei ( null , 0 , parentBindings ) ;
@@ -288,20 +288,20 @@ export function main() {
288288
289289 var protoChild = createPei ( protoParent , 1 , childBindings , 1 , false ) ;
290290 var child = protoChild . instantiate ( parent ) ;
291- child . hydrate ( null , null , defaultPreBuiltObjects ) ;
291+ child . hydrate ( imperativelyCreatedInjector , null , defaultPreBuiltObjects ) ;
292292
293293 return child ;
294294 }
295295
296296 function hostShadowInjectors ( hostBindings : List < any > ,
297- shadowBindings : List < any > ) : ElementInjector {
297+ shadowBindings : List < any > , imperativelyCreatedInjector = null ) : ElementInjector {
298298 var protoHost = createPei ( null , 0 , hostBindings , 0 , true ) ;
299299 var host = protoHost . instantiate ( null ) ;
300300 host . hydrate ( null , null , defaultPreBuiltObjects ) ;
301301
302302 var protoShadow = createPei ( null , 0 , shadowBindings , 0 , false ) ;
303303 var shadow = protoShadow . instantiate ( null ) ;
304- shadow . hydrate ( null , host , null ) ;
304+ shadow . hydrate ( imperativelyCreatedInjector , host , null ) ;
305305
306306 return shadow ;
307307 }
@@ -715,12 +715,32 @@ export function main() {
715715 expect ( shadowInj . get ( NeedsService ) . service ) . toEqual ( 'hostService' ) ;
716716 } ) ;
717717
718- it ( "should instantiate directives that depend on imperativley created injector bindings" , ( ) => {
718+ it ( "should instantiate directives that depend on imperatively created injector bindings (bootstrap) " , ( ) => {
719719 var imperativelyCreatedInjector = Injector . resolveAndCreate ( [
720720 bind ( "service" ) . toValue ( 'appService' )
721721 ] ) ;
722722 var inj = injector ( [ NeedsService ] , imperativelyCreatedInjector ) ;
723723 expect ( inj . get ( NeedsService ) . service ) . toEqual ( 'appService' ) ;
724+
725+ expect ( ( ) => injector ( [ NeedsAncestorService ] , imperativelyCreatedInjector ) ) . toThrowError ( ) ;
726+ } ) ;
727+
728+ it ( "should instantiate directives that depend on imperatively created injector bindings (root injector)" , ( ) => {
729+ var imperativelyCreatedInjector = Injector . resolveAndCreate ( [
730+ bind ( "service" ) . toValue ( 'appService' )
731+ ] ) ;
732+ var inj = hostShadowInjectors ( [ SimpleDirective ] , [ NeedsService , NeedsAncestorService ] , imperativelyCreatedInjector ) ;
733+ expect ( inj . get ( NeedsService ) . service ) . toEqual ( 'appService' ) ;
734+ expect ( inj . get ( NeedsAncestorService ) . service ) . toEqual ( 'appService' ) ;
735+ } ) ;
736+
737+ it ( "should instantiate directives that depend on imperatively created injector bindings (child injector)" , ( ) => {
738+ var imperativelyCreatedInjector = Injector . resolveAndCreate ( [
739+ bind ( "service" ) . toValue ( 'appService' )
740+ ] ) ;
741+ var inj = parentChildInjectors ( [ ] , [ NeedsService , NeedsAncestorService ] , null , imperativelyCreatedInjector ) ;
742+ expect ( inj . get ( NeedsService ) . service ) . toEqual ( 'appService' ) ;
743+ expect ( inj . get ( NeedsAncestorService ) . service ) . toEqual ( 'appService' ) ;
724744 } ) ;
725745
726746 it ( "should prioritize viewInjector over hostInjector for the same binding" , ( ) => {
@@ -1192,7 +1212,7 @@ export function main() {
11921212 } ) ;
11931213 } ) ;
11941214 } ) ;
1195- } ) ;
1215+ } ) ;
11961216}
11971217
11981218class ContextWithHandler {
0 commit comments