[英]How to Invert boolean 'false' in typescript (ionic3 and cordova)
I'm having a somewhat unexpected problem with inverting booleans in my application. 我在应用程序中存在一个与布尔值倒置有关的意外问题。
Environment: I'm having an application, written in typescript with Ionic 3 and I deploy it with help of cordova on an android device. 环境:我有一个应用程序,使用Ionic 3用Typescript编写,并在Cordova的帮助下将其部署在android设备上。
Problem: I'm simply trying to invert a boolean, like shown in the console.log example below: 问题:我只是想反转一个布尔值,如下面的console.log示例所示:
console.log('Clazz: ', clazz.name, ' : ', clazz.boolValue, ' : ', !clazz.boolValue)
Output: 输出:
Clazz: A : true : false
Clazz: B : true : false
Clazz: C : true : false
Clazz: D : false : false
Clazz: E : false : false
Clazz: F : false : false
So, 'true' gets inverted, but 'false' remains the same value. 因此,“ true”取反,但“ false”保持相同的值。 And with that my *ngIf-Directives in Angular do not work as expected.
因此,我在Angular中的* ngIf指令无法按预期工作。
Question: Am I doing something completly wrong? 问题:我做错什么了吗? Or did it just happen, that the combined software versions I'm using do have a glitch together?
还是只是发生了我正在使用的组合软件版本一起出现故障?
This is just a guess but it's probably a decent one, I think your clazz.boolValue
might somehow be a string rather than a boolean at runtime. 这只是一个猜测,但可能是一个不错的猜测,我认为您的
clazz.boolValue
在运行时可能是字符串而不是布尔值。 This would describe the behavior you're seeing. 这将描述您所看到的行为。
!'true' // evaluates to boolean value false
!'false' // also evaluates to boolean value false
Try 尝试
console.log('Clazz: ', clazz.name, ' : ', clazz.boolValue, '|', typeof clazz.boolValue, ' : ', !clazz.boolValue)
to confirm. 确认。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.