• AngularJS学习笔记4


    9.AngularJS  XMLHttpRequest

    $http 是 AngularJS 中的一个核心服务,用于读取远程服务器的数据。

    <div ng-app="myApp" ng-controller="customersCtrl"> 
    
    <ul>
      <li ng-repeat="x in names">
        {{ x.Name + ', ' + x.Country }}
      </li>
    </ul>
    
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.... ")
        .success(function(response) {$scope.names = response.records;});
    });
    </script>

    10.AngularJS  Select(选择框)

    在 AngularJS 中我们可以使用 ng-option 指令来创建一个下拉列表,列表项通过对象和数组循环输出,

    <div ng-app="myApp" ng-controller="myCtrl">
    
    <select ng-model="selectedName" ng-options="x for x in names">
    </select>
    
    </div>

     

    <script>
    
    var app = angular.module('myApp', []);
    app.controller('myCtrl', function($scope) {
        $scope.names = ["Google", "Runoob", "Taobao"];
    });
    
    </script>

    我们也可以使用ng-repeat 指令来创建下拉列表:

    <select>
    <option ng-repeat="x in names">{{x}}</option>
    </select>

    ng-repeat 指令是通过数组来循环 HTML 代码来创建下拉列表,但 ng-options 指令更适合创建下拉列表,它有以下优势:

    使用 ng-options 的选项的一个对象, ng-repeat 是一个字符串。

    11.AngularJS  表格

    <div ng-app="myApp" ng-controller="customersCtrl"> 
    
    <table>
      <tr ng-repeat="x in names">
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
    
    </div>
    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.runoob.com/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });
    </script>

    为了让页面更加美观,我们可以在页面中使用CSS:

    <script>
    var app = angular.module('myApp', []);
    app.controller('customersCtrl', function($scope, $http) {
        $http.get("http://www.runoob.com/try/angularjs/data/Customers_JSON.php")
        .success(function (response) {$scope.names = response.records;});
    });
    </script>

    表格显示序号可以在 <td> 中添加 $index

    <table>
      <tr ng-repeat="x in names">
        <td>{{ $index + 1 }}</td>
        <td>{{ x.Name }}</td>
        <td>{{ x.Country }}</td>
      </tr>
    </table>
  • 相关阅读:
    const,var,let区别(转载)
    在windows上搭建redis集群
    Linux学习笔记—vim程序编辑器
    Linux学习笔记—文件与文件系统的压缩与打包(转载)
    Linux学习笔记—Linux磁盘与文件系统管理(转载)
    五,mysql优化——sql语句优化小技巧
    八,mysql优化——读写分离
    六,mysql优化——小知识点
    七,mysql优化——表的垂直划分和水平划分
    三,mysql优化--sql语句优化之索引一
  • 原文地址:https://www.cnblogs.com/corolcorona/p/6707713.html
Copyright © 2020-2023  润新知