通过第一个点击事件获取第一个接口数据,再通过第二个接口获取第二个接口数据。我用的嵌套,只能获取到第一个的数据。听说promise可以解决,我查找了很多但是都不太能理解,求大神给个详细实例()
var app = angular.module('myApp', []);
app.controller('kmsCtrl', function ($scope, $http) {
$scope.send = function () {
var s = $scope.choice;
var n = $scope.num;
$http({
method: 'JSONP',
url: "http://192.168.18.27:8080/kmx/getWorkCond?type=" + s + "&data=" + n
}).then(function successfulCallback(response) {
$scope.gk = response.data.data;
console.log(response.data);
$scope.sendo = function () {
$http({
method: 'JSONP',
url: 'http://192.168.18.27:8080/kmx/getDatas?deviceIds=(设备id)&sensorNames=&start=&end='
}).then(function successfulCallback(response) {
$scope.d = response.data["0001130667"].TY_0001_00_6;
console.log(response.data["0001130667"])
}, function errorCallback(err) {
});
};
}, function errorCallback(err) {
});
}
如果获取第一个接口的数据只是为了进行获取第二个接口数据,那么我建议你在服务端将接口整合成一个接口,返回合适的数据即可。
如果必须存在嵌套异步的话,可以看下promise知识,比如:https://segmentfault.com/a/11...