Angular Seed - $http.get local json.file

9,410 views
Skip to first unread message

Victor Kurauchi

unread,
Nov 14, 2013, 8:24:08 AM11/14/13
to ang...@googlegroups.com

Hi everyone, i'm new with angular and starting with this seed just now.

https://github.com/angular/angular-seed

Before questions, i already tried the angular-tutorial step5 (http://docs.angularjs.org/tutorial/step_05) and it worked when i wasn't using angular-seed

For a test, the attempt was getting locally saved json (at the root folder /phones.json)

It always returns my whole DOM as response.
I'm assuming it's because my $http.get url is not correct.
In my controller:

$http.get('http://localhost:3000/phones.json')
  .then(function(data) {
    console.log(data);
    $scope.phones = data;
  });

The url param is trying to get some page, right ? But i need to get my json file.
I would like to know where should i put my local json and how should i mention it on url param for $http.get.

Thanks, if u could help me, i appreciate!

Victor Kurauchi

unread,
Nov 14, 2013, 8:41:32 AM11/14/13
to ang...@googlegroups.com
Note: 
Didn't mention but i'm using node/express/socket too. Maybe this issue have something to do with redirects or another thing with node?

thanks

Domenico Matteo

unread,
Nov 15, 2013, 4:41:03 AM11/15/13
to ang...@googlegroups.com
You shouldn't trying to get it from an absolute path (if you're pulling data from your local dirs)

Instead, given the same "seed" dir tree, you could create a new dir inside your app dir, named for example 'content' and store your json there.

Then, you will simply retrieve them with something like this:

    $http.get('/content/your-data.json' ).
        success(function(data) { 
           $scope.text = data 
        });

That's it

Makarand Bhatamrekar

unread,
Nov 15, 2013, 5:41:42 AM11/15/13
to ang...@googlegroups.com
Also,
checkout if you can use $resource, which is more standard way now
http://docs.angularjs.org/api/ngResource.$resource

Victor Kurauchi

unread,
Nov 17, 2013, 9:31:45 AM11/17/13
to ang...@googlegroups.com
thank you guys !!!!


Em quinta-feira, 14 de novembro de 2013 11h24min08s UTC-2, Victor Kurauchi escreveu:
Reply all
Reply to author
Forward
0 new messages