I have a function from a library which is called like this:
example: setMode(CLR.Drop);
There are other options, Drop, Grab, None
So, I've created a method:
selectMode(mode) {
setMode(mode);
}
On a button click I've tried this:
<button (click)="CLR.Drop">Set Mode</button>
When I do the above I get that CLR.Drop is undefined.
So, I've having to pass a number or string like this:
<button (click)="selectMode('drop')">Set Mode</button>
And this have to do this:
selectMode(mode) {
if (mode === 'Drop') {
mode = CLR.Drop;
} else if (mode === 'Grab') {
mode = CLR.Grab;
} else if (mode === 'None') {
mode = CLR.None;
}
setMode(mode);
}
Is there a way to do this without end with lots of if's or a switch or is this the only way?
CLRin a property of component (e.g.CLR = CLR) then your original code will work<button (click)="selectMode('Drop')">Set Mode</button>TS :selectMode(mode) { if (mode == 'Drop') { mode = CLR.Drop; } else if (mode == 'Grab') { mode = CLR.Grab; } else if (mode == 'None') { mode = CLR.None; } setMode(mode); }