Reputation: 1393
I am trying to add Parent annotation in Angular2 alpha31.
I use this import statement:
import {Parent} from 'angular2/annotations';
I have also added the following to angular2.d.ts:
declare module "angular2/annotations" {
function Parent(): (target: any) => any;
function Ancestor(): (target: any) => any;
}
My .ts file looks like this:
/// <reference path='../../../../../typings/angular2/angular2.d.ts' />
import {Component, View} from 'angular2/angular2';
import {Parent} from 'angular2/annotations';
import {Messenger} from 'components/messenger/messenger';
@Component({
selector : 'compose',
hostInjector : [Messenger]
})
@View({
templateUrl: 'components/compose/compose.html'
})
export class Compose {
title : string;
message : string;
messenger : Messenger;
constructor(@Parent messenger:Messenger){
this.messenger = messenger;
}
}
But I keep getting:
Uncaught TypeError: decorator is not a function
What am I missing? :)
Thanks!
Upvotes: 1
Views: 866
Reputation: 4722
I believe the way to do this in alpha-37 is @Host.
constructor(@Host() tabs:Tabs)
Instead of @Parent
, this has at least proved successful to me.
Upvotes: 0
Reputation: 1393
I found the problem:
constructor(@Ancestor @Inject(forwardRef(() => Messenger)) messenger : Messenger) {
this.title = "I am the composer! I am child element of Messenger"
}
Using this and removing "hostInjector : [ Messenger ]" fixed my problem. Thanks for the suggestions.
Upvotes: 1