javascript - 错误在条件表达式中不必要地使用 bool 文字 no-unneeded-ternary

标签 javascript angularjs atom-editor ternary-operator eslint

我正在尝试 codeatomESLint

代码片段:

$scope.IsVisible = false;
$scope.ShowHide = function () {
  $scope.IsVisible = $scope.IsVisible ? false : true; // error
};

得到这个 ESLint 错误:
错误在条件表达式中不必要地使用 bool 文字 no-unneeded-ternary

尝试使用这些解决方案 solution 1solution 2 ,但错误未修复。此外,code在没有 ESLint 的编辑器中工作正常。

最佳答案

尝试好方法=)。在这种情况下不需要使用语句。

$scope.IsVisible = !$scope.IsVisible;

关于javascript - 错误在条件表达式中不必要地使用 bool 文字 no-unneeded-ternary,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42705930/

相关文章:

javascript - 禁用 img 缩放/调整大小? (如何获得 "reveal effect"?)

javascript - 一系列的 promise

javascript - 在 Angular 中声明全局 app 变量是否不好?

python - 无法安装离线atom包

javascript - 在 jquery 中声明一个 if 语句来显示日期

javascript - 匹配带有 [ 字符的行,但如果它有 ] 字符则不匹配

javascript - CORS - Angular 和 Express 的 http OPTIONS 错误

angularjs - 使用 $cordovaImagePicker 插件的 ionic 应用程序中的图像未以正确的格式显示

github - $ git commit --amend 不改变/保存提交信息

sublimetext - Atom.io编辑器中用户代码段的全局范围