Empty data is adding in Table.
I am not able to retrieve data from Json file using Angular Js. I am trying to get the Json data from URL using click function in angular Js and also when click the button add empty tr in table.
var app =angular.module('sampleapp', [])
app.controller("tablejsonCtrl", function ($scope, $http) {
$scope.jsonclick = function () {
var url = "http://127.0.0.1:8000/static/waste/test.json";
$http.get(url).then( function(data) {
$scope.students = data;
});
}
});
<!doctype html>
<html lang="en" ng-app="sampleapp">
<head>
{% load staticfiles %} <!-- <meta charset="utf-8"> -->
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/css/bootstrap.min.css">
<script src = "https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script type="text/javascript" src="{% static 'waste/angular.min.js'%}"></script>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.3.7/js/bootstrap.min.js"></script>
<script type="text/javascript" src="{% static '/bootstrap/js/app_ang.js'%}"></script>
<div class="col-sm-12" ng-controller="tablejsonCtrl">
<button class="clickbutton" value="10" ng-click="jsonclick();">Show-json</button>
<table rule="all" class="table table-bordered table-hover ">
<tr>
<th>Name</th>
<th>Price</th>
<th>Description</th>
<th>Calories</th>
<th>isbest</th>
</tr>
<tr ng-repeat="stuednt in students">
<td>{{stuednt.name}}</td>
<td>{{stuednt.price}}</td>
<td>{{stuednt.description}}</td>
<td>{{stuednt.calories}}</td>
<td>{{stuednt.isbest}}</td>
</tr>
</table>
</div>
</body>
</html>
2
Answers
You need to pass a
response
alongside thedata
that you are fetching.controller
html
json price and calories values should be in double quotes