如何从json获取结果到angularjs

时间:2017-05-02 06:53:36

标签: angularjs json codeigniter-3

美好的一天,我最近了解了angularjs。现在,我正在尝试从表中的json显示数据。我正在使用codeigniter

<script src="<?=base_url();?>assets/app_angular/angular.min.js"></script>
    <script>
    var app = angular.module('myApp', []);
    app.controller('listsupport', function($scope, $http) {
        $http.get("<?=base_url();?>newchat/listsupport").then(function (response) {
                console.log(response);
                $scope.names = response.data.records;
        });
    });
</script>

我有这个Json

    [{"username":"0600260","password":"81dc9bdb52d04dc20036dbd8313ed055","Type":"TP010","Flag":1,"last_login":"1900-01-01 00:00:00.000","loginstatus":0,"alias":null,"FullName":"ZAENAL ABIDIN"},
{"username":"1602762","password":"b59c67bf196a4758191e42f76670ceba","Type":"TP001","Flag":1,"last_login":"2017-05-02 13:43:15.200","loginstatus":1,"alias":"boby","FullName":"BOBY KURNIAWAN"},
 {"username":"0903380","password":"81dc9bdb52d04dc20036dbd8313ed055","Type":"TP010","Flag":1,"last_login":"1900-01-01 00:00:00.000","loginstatus":0,"alias":null,"FullName":"JUDY SJARIP"},
 {"username":"1004385","password":"81dc9bdb52d04dc20036dbd8313ed055","Type":"TP010","Flag":1,"last_login":"1900-01-01 00:00:00.000","loginstatus":0,"alias":null,"FullName":"RENDY SETIAWAN"},
 {"username":"1004502","password":"81dc9bdb52d04dc20036dbd8313ed055","Type":"TP010","Flag":1,"last_login":"1900-01-01 00:00:00.000","loginstatus":0,"alias":null,"FullName":"BANGBANG IRAWAN "},{"username":"1106975","password":"81dc9bdb52d04dc20036dbd8313ed055","Type":"TP010","Flag":1,"last_login":"1900-01-01 00:00:00.000","loginstatus":0,"alias":null,"FullName":"ABDUL ROCHIM"},   {"username":"1501815","password":"81dc9bdb52d04dc20036dbd8313ed055","Type":"TP010","Flag":1,"last_login":"1900-01-01 00:00:00.000","loginstatus":0,"alias":null,"FullName":"KHAIRUNNAS "}]

这是HTML表格

<div ng-app="myApp" ng-controller="listsupport"> 
             <table>
              <tr ng-repeat="x in names">
                <td>{{ x.FullName }}</td>

              </tr>
            </table>
        </div>

使用上面的脚本,我的html是空的。那么如何在我的HTML表格中用角度js显示json?

提前致谢,抱歉我的英语不好。

1 个答案:

答案 0 :(得分:1)

确保您的地址响应在js中正确...我认为您需要像$scope.names = response.data一样了解this plunker

我尝试将你的json数据放入json文件