簡體   English   中英

使用$ ctrl而不是$ scope時在AngularJS中顯示SQL查詢的結果

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

所以我在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];
    });
}
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM