I have a component which takes an argument as a sort of directive to set the size of the <div>
within its template, the only problem now is that I am unsure how to test it?
I call my component like this, where small
can be replaced with other pre-defined sizes such as medium/large
etc:
<spinner small></spinner>
I then take this as an @Input(<size>)
and perform a set to change a size variable that is then passed into an [ngStyle]
to change the CSS of the displayed component size.
component.ts
size: number;
@Input('small') set small(value) {
this.size = !value ? 25 : this.size;
}
get getSize() {
const myStyle = {
width: this.size + 'px',
height: this.size + 'px'
};
return myStyle;
}
component.html
<div [ngStyle]="getSize"></div>
I have successfully tested the get getSize()
function, but I have become a bit stuck around the @Input(<val>) set
functions :-/
Aucun commentaire:
Enregistrer un commentaire