Issue with string attribute in directive

I have an issue with attribute directive.

I have defined following directive:

import {Directive, Input, ElementRef} from 'angular2/core';
@Directive({
    selector: '[chooseMe]'
})

export class ChooseMe {
    @Input('chooseMe') data: string;
    constructor(private _elementRef:ElementRef) {
    console.log(this.data);    
}
}

And I hook it like that:

<button [chooseMe]="example"> W/E</button>

And of course, in my component I have:

@Component({
...,
directives:[ChooseMe]
})

However, each time this.data is undefined. Where is my mistake?

1
Leave a Reply

avatar
1 Comment threads
0 Thread replies
0 Followers
 
Most reacted comment
Hottest comment thread
1 Comment authors
Jason Recent comment authors
  Subscribe  
newest oldest most voted
Notify of
Jason
Guest

Inputs are not set before ngOnChanges() was called the first time.
ngOnInit() is called after the first ngOnChanges():

import {Directive, Input, ElementRef} from 'angular2/core';
@Directive({
    selector: '[chooseMe]'
})
export class ChooseMe {
    @Input('chooseMe') data: string;
    constructor(private _elementRef:ElementRef) {
    }

    ngOnInit() {
        console.log(this.data);    
    }
}