-1

I have an internship where I will be required to use Angular JS HTTP, I want to make sure I can get it to work.

<script> var app = angular.module('myApp', []); app.controller('myCtrl', function($scope, $http) { $http.get("data.json") }); </script> <div ng-app="myApp" ng-controller="myCtrl"> <li ng-repeat="name in Person">{{name.Name}}</li> </div> 

And my JSON file

{ "Name": "Daniel" } 

Thanks,

I'm not sure how to link the url for the JSON file.

5
  • Have you tried actually running the code yet? That would surely be the easiest way to see if it works... Commented Nov 30, 2018 at 19:23
  • 1
    Possible duplicate of How to use HTTP.GET in AngularJS correctly? In specific, for an external API call? Commented Nov 30, 2018 at 19:29
  • Start a server (preferably one that talks http) that delivers data.json? Commented Nov 30, 2018 at 20:01
  • docs.angularjs.org/api/ng/service/$http#general-usage Commented Nov 30, 2018 at 20:24
  • The problem with the suggested duplicate is most of the answers use the deprecated .success and .then methods and the one that uses the .then method is wrong. Commented Dec 1, 2018 at 6:35

1 Answer 1

0

An esay way to start a http-server, if you have node.js on your system, is to use the package http-server. Below is an example using yarn as package manger.

yarn global add http-server cd $TO_THE_DIRECTORY_CONTAINING_DATA.JSON http-server . 

And then you have data.json at: http://localhost:8080/data.json

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.