Как получить доступ к Компоненту по Директиве Angular2?

Я делаю некоторые тесты с Angular 2, и у меня есть директива (layout-item), которая может быть применена ко всем моим компонентам.

Внутри этой директивы я хочу иметь возможность читать некоторые метаданные, определенные для компонента, но для этого мне нужно получить доступ к ссылке на компонент.

Я попробовал следующий подход, но я не смог получить то, что мне нужно. У кого-нибудь есть предложение?

@Component({...})
@View({...})
@MyAnnotation({...})
export class MyComponentA {...}


// Somewhere in a template
<myComponentA layout-item="my config 1"></myComponentA>
<myComponentB layout-item="my config 2"></myComponentA>

// ----------------------

@ng.Directive({
    selector: "[layout-item]",
    properties: [
        "strOptions: layout-item"
    ],
    host: {

    }
})

export class LayoutItem {

    // What works
    constructor(@Optional() @Ancestor({self: true}) private component: MyComponent1) {

 // with the constructor defined like this, component is defined ,with myComponent1 instance.
Reflector.getMetadata("MyAnnotation", component.constructor); // > metadata is here!
    }

// What I needed
    constructor(@Optional() @Ancestor({self: true}) private component: any) {

 // This will crash the app. If instead of any I specify some other type, the app will not crash but component will be null.
 // This directive can be applied to any component, so specifying a type is not a solution. 
    }
}

Ответы на вопрос(5)

Ваш ответ на вопрос