所以我在AngularJS中显示SQL查询结果时遇到问题。
PHP文件完美运行
模板
<table id="penetration">
<tr>
<th>Penetration Pipe 33.1</th>
<th>Penetration Pipe 33.2</th>
</tr>
<tr>
<td>TT0101: <span class="value"></span><br/>
TT0102: <br/>
{{ $ctrl.TT0101Value }}
TT0103: </td>
<td>TT0107: </td>
</tr>
</table>
组件
'use strict';
angular.module('cryostat', []).component('cryostat', {
templateUrl: 'cryostat/cryostat.template.html',
controller: function cryostatController($scope, $http, $q) {
this.pageTitle = "NP04 Cryostat"
this.natalie = 1;
var temp1 = $http.get("cryostat/cryostat.conn.php");
var temp2 = $http.get("cryostat/cryostat.conn.php");
$q.all([temp1, temp2]).then(function (resultArray) {
cryostatController.TT0101 = resultArray[0].data.records;
cryostatController.TT0101Value = cryostatController.TT0101[0].Mnish;
console.log(cryostatController.TT0101Value);
console.log(cryostatController.TT0101[0].Mnish);
// this.TT0102 = resultArray[1];
});
this.httpresult = $http.get("cryostat/cryostat.conn.php")
.then(function (response) {cryostatController.resss = response.data.records;});
}
});
问题是它是空的,即没有显示任何东西,尝试也使用this.TT0101但是这会引发错误未定义
有什么问题?
答案 0 :(得分:0)
抓一点。我自己找到了答案。
将 cryostatController 替换为 self 并添加 var self = this;
'use strict';
angular.module('cryostat', []).component('cryostat', {
templateUrl: 'cryostat/cryostat.template.html',
controller: function cryostatController($scope, $http, $q) {
this.pageTitle = "NP04 Cryostat"
this.natalie = 1;
var self = this;
var temp1 = $http.get("cryostat/cryostat.conn.php");
var temp2 = $http.get("cryostat/cryostat.conn.php");
$q.all([temp1, temp2]).then(function (resultArray) {
self.TT0101 = resultArray[0].data.records;
// this.TT0102 = resultArray[1];
});
}
});