title: Angular user JSON request from a static file
body: <p>I am currently trying to implement this AngularJS example <a href="http://jasonwatmore.com/post/2014/05/26/angularjs-basic-http-authentication-example" rel="nofollow noreferrer">Tutorial Example Login</a> but instead of having the username and password stored as <strong>strings</strong>, I am trying to extract the from a local file. <br></p>
  
  <p><em>I know that this is a bad practice but that is how I am trying to do it.</em></p>
  
  <p>In the section <code>AngularJS Authentication Service. Path: /modules/authentication/services.js</code> in the example, the username and password are stored in a timeout function as:</p>
  
  <pre><code>$timeout(function(){
  var response = { success: username === 'test' &amp;&amp; password === 'test' };
    if(!response.success) {
        response.message = 'Username or password is incorrect';
       }
         callback(response);
  }, 1000);
  </code></pre>
  
  <p>but I am trying to create a static <strong>json</strong> file which holders the username and password as objects. My idea was to make a <code>$http.get</code> request to the file and append the json objects to the username and password parameters like this:</p>
  
  <pre><code>var details;
  $http.get("data.json").then(function(response){
  $scope.details = response.data;
      console.log(username);
  });
  
  
  $timeout(function () {
  var response = { success: username === details.username &amp;&amp; password === details.password 
  if (!response.success) {
     response.message = 'Username or password is incorrect';
  }
   callback(response);
  }, 1000);
  </code></pre>
  
  <p>but I am getting two errors :<br>
  1.<code>ReferenceError: $scope is not defined</code><br>
  2.<code>TypeError: Cannot read property 'username' of undefined</code></p>
  
  <blockquote>
    <p>What is the esiest way to achieve what I am trying to do? Extract the
    username and password from a json file and not have them as a static
    string?</p>
  </blockquote>