I want to use @Input value to initialize other variable in angular 4
export class test {
@Input() id: string;
condition: boolean = (this.id == 'myid') //Getting this.id as undefined
}
You can use id variable directly like id instead of this.id inside a class itself. You have to access variable using this only when variable appeared inside function. But eventually this wouldn't help you, since id value will always be undefined.
Ideally you should use this value inside ngOnInit hook which gets fired when component gets initialized and you will see the value passed from the consumer component.
export class test {
@Input() id: string;
condition: boolean;
ngOnInit(){
this.condition = (this.id == 'myid')
}
}