title: AngularJS Controllers - messy scope boolean values
body: <p>Although my controllers in my AngularJS app are working, I feel they are very messy, hard to maintain and I'm doing something wrong.</p>
  
  <p>In my example, I have two search boxes: <code>ip</code> and <code>port</code>. When validated, these are sent via a POST request and check whether the server exists.</p>
  
  <p>Based on the response, I show a message along with a <code>success</code>, <code>warning</code> or <code>error</code> scope boolean value to trigger what class/colour will be shown.</p>
  
  <p>This works fine, however I will have more validation with more user input boxes afterwards, which means more variables and more mess. Here's an example:</p>
  
  <pre><code>    $scope.server = {};
  
      $scope.success = false;
      $scope.successRcon = false;
  
      $scope.warning = {};
      $scope.error = false;
      $scope.errorRcon = false;
  
      $scope.message = false;
      $scope.messageRcon = false;
  
      $scope.warning.main = false;
      $scope.warning.ip = false;
      $scope.warning.port = false;
  
      $scope.searching = false;
      $scope.found = false;
  
      $scope.adding = false;
      $scope.addUserError = false;
  
      $scope.validating = false;
  
      $scope.search = function(server)
      {
          if (! angular.isDefined(server.ip) || ! validateIp(server.ip))
          {
              $scope.success = false;
              $scope.warning.main = true;
  
              $scope.warning.ip = true;
              $scope.error = false;
  
              $scope.searching = false;
  
              $scope.message = 'Please enter a valid IP address!';
          }
          else if(! angular.isDefined(server.port) || ! validateNumber(server.port))
          {
              $scope.success = false;
              $scope.warning.main = true;
  
              $scope.warning.ip = false;
              $scope.warning.port = true;
              $scope.error = false;
  
              $scope.searching = false;
  
              $scope.message = 'Please enter a valid port number!';
          }
          else
          {
              $scope.success = false;
              $scope.warning.main = false;
              $scope.error = false;
  
              $scope.warning.ip = false;
              $scope.warning.port = false;
  
              $scope.searching = true;
  
              $scope.message = false;
  
              // http post request, the response also sets some of these values
         }
     };
  </code></pre>
  
  <p>As you can see, this is pretty horrendous.. Any solution to doing something like this?</p>