Reputation: 2748
Good day, I recently learn about angularjs. Now, i'm trying to show data from json in table. I'm using 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>
I have this 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 "}]
and here is HTML table
<div ng-app="myApp" ng-controller="listsupport">
<table>
<tr ng-repeat="x in names">
<td>{{ x.FullName }}</td>
</tr>
</table>
</div>
With my script above, my html is empty. So how can i show the json in my HTML table with angular js ?
Thanks in advance and sorry for my bad english.
Upvotes: 2
Views: 225
Reputation: 2075
make sure your addressing response properly in js...i think u need to give like $scope.names = response.data
have a look on this plunker
i tried with placing ur json data in to a json file
Upvotes: 1