Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/25.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript AngularJS:如何在AngularJS中优化下面的if/else语句?_Javascript_Angularjs_Angularjs Directive - Fatal编程技术网

Javascript AngularJS:如何在AngularJS中优化下面的if/else语句?

Javascript AngularJS:如何在AngularJS中优化下面的if/else语句?,javascript,angularjs,angularjs-directive,Javascript,Angularjs,Angularjs Directive,如何优化/减少angularjs下面if/else语句的代码行 if($scope.menuActive === true) { $rootScope.menuActiveStatus = true; } else { $rootScope.menuActiveStatus=false; } 你是说在线 $rootScope.menuActiveStatus = $scope.menuActive === true; 您还可以基于$scope.

如何优化/减少angularjs下面if/else语句的代码行

if($scope.menuActive === true)
  { 
       $rootScope.menuActiveStatus = true;
  }

  else {
       $rootScope.menuActiveStatus=false;
  }
你是说在线

$rootScope.menuActiveStatus = $scope.menuActive === true;
您还可以基于$scope.menuActive===true条件设置任何其他值,例如:

$rootScope.menuActiveStatus = $scope.menuActive === true ? "YES!" : "NO :("; // Ternary operator example
你是说在线

$rootScope.menuActiveStatus = $scope.menuActive === true;
您还可以基于$scope.menuActive===true条件设置任何其他值,例如:

$rootScope.menuActiveStatus = $scope.menuActive === true ? "YES!" : "NO :("; // Ternary operator example