问题
I have this function that runs after a multiselect element is changed that sets an error message visibility:
getVisibility(multiselect) {
if ((multiselect.selectedCategories.length < 1 && !multiselect.allSelected) && this.submitted) {
return 'visible'
} else {
return 'hidden'
}
}
However in this line:
if ((multiselect.selectedCategories.length < 1 && !multiselect.allSelected) && this.submitted)
multiselect.allSelected is false, but !multiselect.allSelected is also false.
picture1:
picture2:
Why is the ! (not) the same boolean value as without the not?
回答1:
Typescript not operator not working
Its just JavaScript in the end and it most definitely works. The issue with the chrome dev tools and / or TypeScript source maps.
What I do:
- Execute the command in the console (hovers can lie).
- Disable source maps (More reasons : Chrome Typescript debugging references wrong 'this')
来源:https://stackoverflow.com/questions/39186189/typescript-not-operator-not-working