简体   繁体   English

使用$ ctrl而不是$ scope时在AngularJS中显示SQL查询的结果

[英]Display results of SQL query in AngularJS when using $ctrl instead of $scope

So I have a problem displaying result of SQL query in AngularJS. 所以我在AngularJS中显示SQL查询的结果时遇到问题。

PHP file works perfectly PHP文件完美运行

Template 模板

<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>

Component 零件

'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;});
}
});

The problem is that it's empty, ie doesn't display anything, tried also using this.TT0101 but this throws error undefined 问题是它为空,即不显示任何内容,也尝试使用this.TT0101,但这会引发未定义的错误

What is the problem? 问题是什么?

Scratch that. 从头开始。 Found an answer myself. 我自己找到了答案。

Replaced cryostatController with self and added var self = this; 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];
    });
}
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM