title: can't get access to angular.js $cookies object
body: <p>I am using the angular.js and csrf (Cross-site request forgery).</p>
  
  <p>I have added the angular cookie file.</p>
  
  <pre><code>script src="angular-cookies.js"
  </code></pre>
  
  <p>And then, to load it in the application:</p>
  
  <pre><code>angular.module('myApp', ['ngCookies']);
  </code></pre>
  
  <p>It’s really easy to add the CSRF token in the headers of the $http service. We just need to configure it into the run process of the application, requiring the $cookie and $http services.</p>
  
  <pre><code>  .run(function ($http, $cookies) {
      $http.defaults.headers.post['x-csrf-token'] = $cookies._csrf;
    });
  </code></pre>
  
  <p>in the browser debug console, I can find the cookie is existing.
  However,when the page is loaded, $cookies outputs undefined, it is strange the $cookies object itself is undefined, but obviously I have loaded the cookie.js and inject the module into the application</p>
  
  <p>This is on the node.js server side, which how I set a CSRF token on the cookie</p>
  
  <pre><code>  app.use(require('csurf')()); 
    app.use(function(req, res, next){
    res.locals.token = req.csrfToken(); 
    res.cookie('XSRF_TOKEN', req.csrfToken(),{ maxAge: 900000, httpOnly: false });
    next();
  });
  </code></pre>
  
  <p>Thanks for the reminding, I changed the </p>
  
  <pre><code>  res.cookie('XSRF_TOKEN', req.csrfToken(),{ maxAge: 900000 });
  </code></pre>
  
  <p>to </p>
  
  <pre><code>  res.cookie('XSRF_TOKEN', req.csrfToken(),{ maxAge: 900000, httpOnly: false });
  </code></pre>
  
  <p>so the cookie is readable from the browser.</p>