我正在尝试$ http服务代码,但没有得到结果
这是samp.html的代码
foreach(var item in list_Stuctures)
{
lst_DataStructure.ADD(item);
}
<!DOCTYPE html>
<html>
<head>
<title>
AngularJs $http Service Example
</title>
<script
src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js">
</script>
<script type="text/javascript">
var app = angular.module('serviceApp', []);
app.controller('serviceCtrl', function ($scope, $http) {
$http({
method: 'GET',
url: 'welcome.html'
}).then(function success(response) {
$scope.myWelcome = response.myWelcome;
}, function error(response) {
});
});
````````````````````````````````这是welcome.html````的代码```````
<div ng-app="serviceApp" ng-controller="serviceCtrl">
<p>Hi, Guest</p>
<h1>{{myWelcome}}</h1>
</div>
答案 0 :(得分:1)
$ http服务将数据作为响应对象的data
属性返回:
var app = angular.module('serviceApp', []);
app.controller('serviceCtrl', function ($scope, $http) {
$http({method: 'GET',url: 'welcome.html'})
.then(function success(response) {
̶$̶s̶c̶o̶p̶e̶.̶m̶y̶W̶e̶l̶c̶o̶m̶e̶ ̶=̶ ̶r̶e̶s̶p̶o̶n̶s̶e̶.̶m̶y̶W̶e̶l̶c̶o̶m̶e̶;̶
$scope.myWelcome = response.data.myWelcome;
console.log(response.data);
}).catch(function(error) {
console.log(error);
throw error;
});
});
有关更多信息,请参见