gpt4 book ai didi

javascript - AngularJS $http 获取数据,但未显示。

转载 作者:行者123 更新时间:2023-12-02 14:55:34 25 4
gpt4 key购买 nike

刚接触 AngularJs,并坚持使用 $http 异步获取数据,但不绑定(bind)/显示数据。

console.log 显示数据传输正常。但是,由于数据是异步传入的,因此数据是在页面加载后传入的。

<!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>

最佳答案

ng-repat更改为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>

关于javascript - AngularJS $http 获取数据,但未显示。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35836473/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com