【发布时间】:2017-03-13 14:21:37
【问题描述】:
我想显示产品,需要通过连接到 api(使用令牌)来发出获取请求,以便使用 angular 获取产品(显示)。我真的不知道 如何做到这一点,尝试像在 Angular 的文档中那样做,但它不起作用。任何帮助,将不胜感激。谢谢! 角度:
var app = angular.module('myApp', []);
app.controller('myAppCtrl', function($scope, $http) {
$http({
method: 'GET',
url: 'http://testing.com/page/go',
config: {
params: {
token: "1234x.1234x",
}
}
})
.then(function(products) {
products.data;
})
.then(function(allProducts) {
$scope.products = allProducts;
})
});
html:
<body ng-app="myApp" ng-controller="myAppCtrl">
<div>
<ul>
<li ng-repeat="product in products"> {{product}} </li>
</ul>
</div>
</body>
【问题讨论】:
-
"products.data;" 什么都不做。您可能需要添加一个 return 语句。
-
如果我返回 products.data,什么也不会发生