您可以使用.then()
方法来处理$http
的响应,并将返回的结果更新到您的变量中。
请参考以下示例代码:
// 在控制器中定义一个变量来存储返回的JSON结果
$scope.data = {};
// 使用$http服务发送GET请求
$http.get('api/data').then(function(response) {
// 将返回的JSON结果更新到变量中
$scope.data = response.data;
}).catch(function(error) {
// 处理错误
console.log(error);
});
在上面的代码中,我们使用$http.get()
方法发送一个GET请求到api/data
接口,并使用.then()
方法来处理成功的响应。在.then()
方法中,我们将返回的JSON结果通过response.data
赋值给$scope.data
变量。
请确保替换'api/data'
为您实际的API接口地址。
这样,当请求成功时,$scope.data
变量将被更新为返回的JSON结果。