title: getting JSON data into an angularJS service and comparing for login
body: <p>I have a nodejs server setup. It is pulling data from my database and turning it into JSON to be pulled from my NodeJS server.</p>
  
  <p>I have this service:</p>
  
  <pre><code>.service('LoginService', function ($q) {
     return {
        loginUser: function (name, pw) {
            var deferred = $q.defer();
            var promise = deferred.promise;
  
            if (name == 'user' &amp;&amp; pw == 'secret') {
                deferred.resolve('Welcome ' + name + '!');
            } else {
                deferred.reject('Wrong credentials.');
            }
            promise.success = function (fn) {
                promise.then(fn);
                return promise;
            }
            promise.error = function (fn) {
                promise.then(null, fn);
                return promise;
            }
            return promise;
        }
     }
  })
  </code></pre>
  
  <p>Now in this I am comparing the input by the user for password and username to <code>user</code> and <code>secret</code>. Now that I have some JSON data on my server I would like to iterate through that and compare it to <code>name</code> and <code>pw</code> in my service.</p>
  
  <p>So I think its something like this but I think its a syntax error</p>
  
  <pre><code>$http.get("http://***.***.**.***:****/login").success(function(data) {
     $scope.user = data
  });
  angular.forEach(data, function(username, key) {
     if(name == $scope.username &amp;&amp; pw == $scope.password) { 
       //login code from above
     }
  });
  </code></pre>
  
  <p>My angularJS syntax is way off, I'm still learning. I'm not sure I'm even aloud to use <code>$scope</code> in a service. </p>
  
  <p>So really what Im looking for is to iterate through my values in the JSON and compare them to the values entered by the user. </p>
  
  <p><strong>Edit 1</strong></p>
  
  <p>Here I will add More background to the project to help you understand what I am doing and why.</p>
  
  <p>I have a google cloud SQL database that I have added records to with MySQL work bench. In the database there is a users table, this contains information like name, age gender, email, password etc. I have 2 records in this table.</p>
  
  <p>I also have a google nodeJS server that I use to access the database records and return them as JSON from a web address (http://:/load). </p>
  
  <p>This is why I would Like my login attempt to check the JSON array for the username and password. the password is unencrypted atm but I just want my basic functionality in there first that checks if the values are equal.</p>
  
  <p>I hope this makes it more clear</p>