在 AngularJS 页面上显示多个 Oracle SQL 查询结果
Display multiple Oracle SQL query results on AngularJS page
因此我需要在 AngularJS 中的同一组件上显示 SQL 查询的多个结果。
我该怎么做?到目前为止,我了解到组件只能处理一个 http 请求,如下所示:
'use strict';
angular.module('cryostat', []).component('cryostat', {
templateUrl: 'cryostat/cryostat.template.html',
controller: function cryostatController($http) {
this.pageTitle = "NP04 Cryostat"
this.natalie = 1;
$http.get("cryostat.conn.php")
.then(function (response) {this.TT0101 = response.data.records;});
}
});
I understood that component can treat only one http request
这根本不是真的。你是从哪里听来的?使用 $q.all()
:
同时发出两个请求很容易
var promiseOne = $http.get("query1.php");
var promiseTwo = $http.get("query2.php");
$q.all([promiseOne, promiseTwo]).then(function(resultArray) {
$scope.resultOne = resultArray[0];
$scope.resultTwo = resultArray[1];
});
根据您的目的使用 $q.all()
。
var myData_One, myData_two;
var promises = [];
function promiseA() {
let deferred = $q.defer();
ajaxCall().then((response) => {
$scope.myData_One = response;
deferred.resolve();
}, (error) => {
deferred.reject(error);
});
return deferred.promise;
}
function promiseB() {
let deferred = $q.defer();
ajaxCall().then((response) => {
$scope.myData_two = response;
deferred.resolve(response);
}, (error) => {
deferred.reject(error);
});
return deferred.promise;
}
var promises = [promiseA(), promiseB()];
$q.all(promises).then((values) => {
//Do whatever you wish to with response data from both promises.
});
因此我需要在 AngularJS 中的同一组件上显示 SQL 查询的多个结果。
我该怎么做?到目前为止,我了解到组件只能处理一个 http 请求,如下所示:
'use strict';
angular.module('cryostat', []).component('cryostat', {
templateUrl: 'cryostat/cryostat.template.html',
controller: function cryostatController($http) {
this.pageTitle = "NP04 Cryostat"
this.natalie = 1;
$http.get("cryostat.conn.php")
.then(function (response) {this.TT0101 = response.data.records;});
}
});
I understood that component can treat only one http request
这根本不是真的。你是从哪里听来的?使用 $q.all()
:
var promiseOne = $http.get("query1.php");
var promiseTwo = $http.get("query2.php");
$q.all([promiseOne, promiseTwo]).then(function(resultArray) {
$scope.resultOne = resultArray[0];
$scope.resultTwo = resultArray[1];
});
根据您的目的使用 $q.all()
。
var myData_One, myData_two;
var promises = [];
function promiseA() {
let deferred = $q.defer();
ajaxCall().then((response) => {
$scope.myData_One = response;
deferred.resolve();
}, (error) => {
deferred.reject(error);
});
return deferred.promise;
}
function promiseB() {
let deferred = $q.defer();
ajaxCall().then((response) => {
$scope.myData_two = response;
deferred.resolve(response);
}, (error) => {
deferred.reject(error);
});
return deferred.promise;
}
var promises = [promiseA(), promiseB()];
$q.all(promises).then((values) => {
//Do whatever you wish to with response data from both promises.
});