0

I'm trying to follow along a AngularJS tutorial about making a Email Client.

I downloaded the source code with all chapters from 01 to 07. Started my own project in a folder called "Application".

Project Folder

The code is running without throwing any errors, but the thing is that it's the wrong JSON file that is being loaded!

I copied the json from 04 and changed the first from to be Hello World (originally TicketFactory). Changed every others json files to contain their location, so chapter 04 became TicketFactory chapter 04 and so on.

Now starting the server in the Application directory gives me this:

Console

browser result

I have no clue where it is getting this .json file..? Perhaps an old GET request?

My code looks like this

InboxFactory.js

(function() {
  'use strict';

  angular
    .module('EmailApp')
    .factory('InboxFactory', myfactory);

  myfactory.$inject = ['$q','$http', '$location'];

  function myfactory($q, $http, $location){
    var exports = {};

    exports.getMessages = function () {
      return $http.get('json/emails.json')
        .error(function(data) {
          console.log('There was an error!', data);
        });
    };

    return exports;
  }

})();

It might look a bit different from the tutorial because I used Atom's AngularJS snippet package. But it looks good enough for me, but then again - I'm still learning!

1
  • I found the emails.json under Network and saw that it got it from cache. I then cleared the browser cache and it worked. Commented Feb 6, 2016 at 22:43

2 Answers 2

1

It also could be a cache problem !

Do F12, and check the "Network" tabs (with an F5...): you will retry the full path of the file, it's contents,...

Sign up to request clarification or add additional context in comments.

5 Comments

I have tried to refresh it a couple of times and no luck.
Have you checked the path displayed in the "referer" field , in the "Network" tabs ?
arhh sorry I misunderstoood you.
It doesn't seem useful to me to use cache when the content in the cache is outdated... or am I missing something?
Yes, of course, but it's your web browser which manages the cache and decides to read or not on the server. In general, if the URL does not change (file name or identical parameter), the browser can assume that the file has not changed on the server and not read it again ... One method to force the reload of the json file would be to add a timestamp parameter : return $http.get('json/emails.json?d=160206203051')
0
return $http.get('json/emails.json')

This is misleading because you have multiple json folders containing emails.json on your project root.

Try : return $http.get('../Application/json/emails.json')

2 Comments

That didn't work.. gave an error 404 in the console - File not found. The header My Inbox loaded just fine..
What was error log on the console ? where did it tried to fetch the json ?

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.