Compared with jquery, angular is much more convenient for data processing on this interface. This example calls the API interface of the China Weather Network.
First of all, I'm going to introduce angular.js.
<link rel="stylesheet" href="css/bootstrap.css" type="text/css"></link>
<script type="text/javascript" src="./js/angular.js"></script>
Next JS code is as follows:
var app = angular.module("myApp", []);
app.controller("myCtrl", [‘$scope‘,‘$http‘, function($scope,$http) { var url=‘http://wthrcdn.etouch.cn/weather_mini?city=‘+‘北京‘;
$http.get(url).then(function (response) {
$scope.cityname=response.data.data.city
$scope.myweather= response.data.data.forecast;
});
}]);
Use Ng-app to manage the ANGULARJS scope, the controller Ng-controller this to write your method. These are all necessary.
div Code:
<body ng-app = "myApp">
<div ng-controller = "myCtrl">
<div>
<p style = "font-size: 18px; text-align: center; font-weight: 600; color: rgb (200,10,10)"> {{cityname}} </ p>
<table class = "table" id = "tale">
<th> date </ th>
<th> Wind power </ th>
<th> Wind direction </ th>
<th> Maximum temperature </ th>
<th> Minimum temperature </ th>
<th> Weather conditions </ th>
<tr ng-repeat = "i in myweather">
<td> {{i.date}} </ td>
<td> {{i.fengli}} </ td>
<td> {{i.fengxiang}} </ td>
<td> {{i.high}} </ td>
<td> {{i.low}} </ td>
<td> {{i.type}} </ td>
</ tr>
</ table>
</ div>
</ body>
It's very handy here: Ng-repeat, cycle through the data you want to print. Of course you will encounter something like this later:
This is because you have the same data in your array, so you just need to add "track by $index" to the ng-repeat, such as ng-repeat= "I in your data track by $index".
The page shows as follows:
Angularjs simple drop interface for array page printing