0

New to AngularJs and stuck with $http getting data asynchronously, but not binding / showing the data.

The console.log is showing that the data is coming through alright. However, since the data is coming in asynchronously, the data is coming in after the page has already loaded.

<!DOCTYPE html>
<html>
<head>

<title>Iterate over data from Webservice.</title>
<script
	src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>

<!-- This is the angularjs magic. -->
<script>
	var app = angular.module('myApp', []);
	app.controller('myController', function($scope, $http) {

		/* Lets get some data from an actual service.  */
		$http.get("http://www.w3schools.com/angular/customers.php").then(
				function(response) {
					console.log("This is what came back -"
							+ response.data.records);
					$scope.names = response.data.records;
				});
	});
</script>


</head>
<body>

	<h1>Get data from a webservice and show it on the page.</h1>

	<div ng-app="myApp" ng-controller="myController">

		<ul>
			<li ng-repat="x in names">Name[{{x.Name}}]</li>
		</ul>
	</div>

</body>
</html>

1
  • 3
    You have a mispelling ng-repat Commented Mar 7, 2016 at 5:06

1 Answer 1

2

change ng-repat to ng-repeat

var app = angular.module('myApp', []);
	app.controller('myController', function($scope, $http) {

		/* Lets get some data from an actual service.  */
		$http.get("http://www.w3schools.com/angular/customers.php").then(
				function(response) {
					console.log("This is what came back -"
							+ response.data.records);
					$scope.names = response.data.records;
				});
      
      $scope.test = "tes1t";
      
	});
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<body>

	<h1>Get data from a webservice and show it on the page.</h1>

	<div ng-app="myApp" ng-controller="myController">

		<ul>
			<li ng-repeat="x in names">Name[{{x.Name}}]</li> <!-Here ng-repeat ->
		</ul>
	</div>

</body>

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

3 Comments

Thanks. I should have invested more time on getting a good set of dev tools.
@mishtusorous what are you using now..Recommend you to use either Sublime Text or Brackets if you are working on angular
I am using Eclipse at the moment. I need something that has autocomplete.

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.