zoukankan      html  css  js  c++  java
  • AngularJS快速入门指南17:Includes

      使用AngularJS,你可以在HTML中包含其它的HTML文件。


    在HTML中包含其它HTML文件?

      当前的HTML文档还不支持该功能。不过W3C建议在后续的HTML版本中增加HTML imports功能,以支持在HTML中包含其它的HTML文件。

    <link rel="import" href="/path/navigation.html">

    在服务端包含文件

      大部分的web服务器都支持服务端包含文件(Server Side Includes)。通过使用SSI,你可以在页面被发送到客户端浏览器之前将HTML文件包含到一段HTML文档中。例如下面的这行PHP代码:

    <?php require("navigation.php"); ?>

    在客户端包含文件

      通过JavaScript,我们可以有许多的方法将HTML文件加入到HTML文档中。

      最通用的做法莫过于使用Ajax,即通过异步http请求从服务端获取数据,然后动态将内容以innerHTML的形式输出到HTML元素中。


    在AngularJS中包含文件

      在AngularJS中,你可以使用ng-include指令将HTML文件加入到HTML文档中:

    <body>
    
    <div class="container">
      <div ng-include="'myUsers_List.htm'"></div>
      <div ng-include="'myUsers_Form.htm'"></div>
    </div>
    
    </body>

      下面是完成上述页面的三个步骤。


    第一步:创建myUsers_List.htm文件

    <h3>Users</h3>
    
    <table class="table table-striped">
      <thead><tr>
        <th>Edit</th>
        <th>First Name</th>
        <th>Last Name</th>
      </tr></thead>
      <tbody><tr ng-repeat="user in users">
        <td>
          <button class="btn" ng-click="editUser(user.id)">
            <span class="glyphicon glyphicon-pencil"></span>&nbsp;&nbsp;Edit
          </button>
        </td>
        <td>{{ user.fName }}</td>
        <td>{{ user.lName }}</td>
      </tr></tbody>
    </table>

    第二步:创建myUsers_Form.htm文件

    <button class="btn btn-success" ng-click="editUser('new')">
      <span class="glyphicon glyphicon-user"></span> Create New User
    </button>
    <hr>
    
    <h3 ng-show="edit">Create New User:</h3>
    <h3 ng-hide="edit">Edit User:</h3>
    
    <form class="form-horizontal">
    <div class="form-group">
      <label class="col-sm-2 control-label">First Name:</label>
      <div class="col-sm-10">
        <input type="text" ng-model="fName" ng-disabled="!edit" placeholder="First Name">
      </div>
    </div> 
    <div class="form-group">
      <label class="col-sm-2 control-label">Last Name:</label>
      <div class="col-sm-10">
        <input type="text" ng-model="lName" ng-disabled="!edit" placeholder="Last Name">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">Password:</label>
      <div class="col-sm-10">
        <input type="password" ng-model="passw1" placeholder="Password">
      </div>
    </div>
    <div class="form-group">
      <label class="col-sm-2 control-label">Repeat:</label>
      <div class="col-sm-10">
        <input type="password" ng-model="passw2" placeholder="Repeat Password">
      </div>
    </div>
    </form>
    
    <hr>
    <button class="btn btn-success" ng-disabled="error || incomplete">
      <span class="glyphicon glyphicon-save"></span> Save Changes
    </button>

    第三步:创建主页面文件

    <!DOCTYPE html>
    <html ng-app="">
    <link rel="stylesheet" href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
    <script src= "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"></script>
    <body ng-controller="userCtrl">
    
    <div class="container">
    <div ng-include="'myUsers_List.htm'"></div>
    <div ng-include="'myUsers_Form.htm'"></div>
    </div>
    
    <script src= "myUsers.js"></script>
    
    </body>
    </html>
  • 相关阅读:
    Python的扩展接口[1] -> 串口通信
    Python的扩展接口[0] -> VISA仪器控制
    Python的工具包[2] -> matplotlib图像绘制 -> matplotlib 库及使用总结
    Python的工具包[1] -> pandas数据预处理 -> pandas 库及使用总结
    Python的工具包[0] -> numpy科学计算 -> numpy 库及使用总结
    Python的Web编程[1] -> Web服务器[0] -> Web 服务器与 CGI / WSGI
    Python的Web编程[0] -> Web客户端[1] -> Web 页面解析
    Python的Web编程[0] -> Web客户端[0] -> 统一资源定位符 URL
    Python与正则表达式[0] -> re 模块的正则表达式匹配
    解决Wamp的 Error D:wamp or PHP path 错误
  • 原文地址:https://www.cnblogs.com/jaxu/p/4507300.html
Copyright © 2011-2022 走看看