When passing an attribute into my Angular component like this:
<my-component myAttribute></my-component>
I aim to modify a variable within the component that controls the CSS properties for width
and height
.
To simplify, I have predefined attribute values set up where using:
<my-component large>
Will automatically adjust the width
and height
variables to be 100
(resulting in 100px).
However, I am exploring the possibility of creating multiple criteria using @Input()
without having numerous separate entries. Instead, could I potentially utilize a switch statement to achieve the same outcome?
I have made some attempts at implementing this approach, but all I see are red squiggly lines under the code.
My Inputs:
size = 50 // Default value
@Input('small') set small(value) {
this.size = !value ? 25 : this.size;
}
@Input('medium') set medium(value) {
this.size = !value ? 50 : this.size;
}
@Input('large') set large(value) {
this.size = !value ? 100 : this.size;
}
@Input('x-large') set xlarge(value) {
this.size = !value ? 200 : this.size;
}