html - 使用 $ctrl 而不是 $scope 时在 AngularJS 中显示 SQL 查询的结果
问题描述
所以我在 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 但这会引发错误未定义
问题是什么?
解决方案
刮那个。自己找到了答案。
用self替换了cryostatController并添加了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];
});
}
});
推荐阅读
- android - 如何调试错误“AAPT2 错误:检查日志以获取详细信息”?
- php - 使用 PDO 获取单个数据并存储在变量中
- javascript - 如何在开发过程中向文档添加属性,但不保存到数据库?
- java - PDFClown:如何克隆页面
- yocto - 用 Yocto 编译 Dlib 库
- c++ - VisualStudio 2010 C++ 颜色主题
- asp.net-mvc - MVC:无法弄清楚这段代码是如何命中存储过程的
- wordpress - 更新插件时出现 WordPress HTTP ERROR 500
- php - 在 Woocommerce 3 中隐藏特定产品的购物车中的数量字段
- drupal-8 - 通过扩展其路径来渲染具有多种显示模式的节点