@@ -16,6 +16,7 @@ import {BindingPropagationConfig} from 'angular2/src/core/compiler/binding_propa
1616
1717import { Decorator , Component , Viewport } from 'angular2/src/core/annotations/annotations' ;
1818import { Template } from 'angular2/src/core/annotations/template' ;
19+ import { Parent , Ancestor } from 'angular2/src/core/annotations/visibility' ;
1920
2021import { ViewContainer } from 'angular2/src/core/compiler/view_container' ;
2122
@@ -296,6 +297,43 @@ export function main() {
296297 done ( ) ;
297298 } )
298299 } ) ;
300+
301+ it ( 'should create a component that injects a @Parent' , ( done ) => {
302+ tplResolver . setTemplate ( MyComp , new Template ( {
303+ inline : '<some-directive><cmp-with-parent #child></cmp-with-parent></some-directive>' ,
304+ directives : [ SomeDirective , CompWithParent ]
305+ } ) ) ;
306+
307+ compiler . compile ( MyComp ) . then ( ( pv ) => {
308+ createView ( pv ) ;
309+
310+ var childComponent = view . contextWithLocals . get ( 'child' ) ;
311+ expect ( childComponent . myParent ) . toBeAnInstanceOf ( SomeDirective ) ;
312+
313+ done ( ) ;
314+ } )
315+ } ) ;
316+
317+ it ( 'should create a component that injects an @Ancestor' , ( done ) => {
318+ tplResolver . setTemplate ( MyComp , new Template ( {
319+ inline : `
320+ <some-directive>
321+ <p>
322+ <cmp-with-ancestor #child></cmp-with-ancestor>
323+ </p>
324+ </some-directive>` ,
325+ directives : [ SomeDirective , CompWithAncestor ]
326+ } ) ) ;
327+
328+ compiler . compile ( MyComp ) . then ( ( pv ) => {
329+ createView ( pv ) ;
330+
331+ var childComponent = view . contextWithLocals . get ( 'child' ) ;
332+ expect ( childComponent . myAncestor ) . toBeAnInstanceOf ( SomeDirective ) ;
333+
334+ done ( ) ;
335+ } )
336+ } ) ;
299337 } ) ;
300338 } ) ;
301339}
@@ -358,6 +396,39 @@ class ChildComp {
358396 }
359397}
360398
399+ @Decorator ( {
400+ selector : 'some-directive'
401+ } )
402+ class SomeDirective { }
403+
404+ @Component ( {
405+ selector : 'cmp-with-parent'
406+ } )
407+ @Template ( {
408+ inline : '<p>Component with an injected parent</p>' ,
409+ directives : [ SomeDirective ]
410+ } )
411+ class CompWithParent {
412+ myParent : SomeDirective ;
413+ constructor ( @Parent ( ) someComp : SomeDirective ) {
414+ this . myParent = someComp ;
415+ }
416+ }
417+
418+ @Component ( {
419+ selector : 'cmp-with-ancestor'
420+ } )
421+ @Template ( {
422+ inline : '<p>Component with an injected ancestor</p>' ,
423+ directives : [ SomeDirective ]
424+ } )
425+ class CompWithAncestor {
426+ myAncestor : SomeDirective ;
427+ constructor ( @Ancestor ( ) someComp : SomeDirective ) {
428+ this . myAncestor = someComp ;
429+ }
430+ }
431+
361432@Viewport ( {
362433 selector : '[some-viewport]'
363434} )
0 commit comments