1

How do i optimize/reduce line of code of the below if/else statements of angularjs

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

  else {
       $rootScope.menuActiveStatus=false;
  }

1 Answer 1

4

You mean inline?

$rootScope.menuActiveStatus = $scope.menuActive === true;

You can also set any other value based on the $scope.menuActive === true condition (Just for example):

$rootScope.menuActiveStatus = $scope.menuActive === true ? "YES!" : "NO :("; // Ternary operator example
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.