It is possible to send number or a whole class instance to @Input ?
I am trying to send the value like this value="id" or this [value]="id".
for example id = 1.But in console i see that my object received string value id and not the value of id, those = 1.
In console i see this:
id : id
typeof: string
UPDATED
My class that store value:
private id: number ;
show(id: number): void {
this.id = id;
}
In html page of my component i assign to selector of my childComponent value like this value="id" or this [value]="id".
And my child class is very simple:
@Input() value: number;
constructor() {
}
ngOnChanges() {
console.log(`ngOnChanges: `, this.value);
}
It is possible to send number or a whole class instance to @Input ?
Yes, it is possible.
Notes:
[value]="'Justastring'".For @Input() bound attributes, the common way is [value]="id".
Angular will now simply look for variable named id in the component's class and assign the value to the value variable in the child component.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With