Angularjs simple drop interface for array page printing

Source: Internet
Author: User



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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.