Directive Component Life-cycle? @Input() value in the constructor


#1

Good afternoon, everyone.

I have something to ask.

I want to know why ‘this.slug’ in the constructor is ‘undefined’ while {{ slug }} in the template has right value when it is called(used) in parent component’s template.

Is there anything I am missing on the understanding of component life cycle?

@Component({
    selector: 'abcd',
    template: `
        <h2>Post List</h2>
        {{ slug }}
    `
})
export class PostListComponent {
    @Input() slug: string;
    constructor() {
        console.log('PostListComponent::constructor()', this.slug);
   }

#2

did u get any answer


#3

The best place to work with @Input properties is in ngOnChanges.