码迷,mamicode.com
首页 > Web开发 > 详细

angular.js包含

时间:2017-02-24 13:37:13      阅读:217      评论:0      收藏:0      [点我收藏+]

标签:module   response   ctr   asc   lis   访问   resource   http请求   example   

AngularJS包含

 

在html中包含html文件

在html中,目前还不支持包含html的文件的功能。

 

服务端包含

大多数服务器脚本都支持包含文件功能(SSI:servier side Includes)

使用SSI,你可以在HTML中包含html文件,并发送到客户端浏览器。

<?php require("navigation.php")>  //PHP中

<%@ include  file="../tkheader.jsp" %>   //在Jsp中

 

在客户端包含

通过javascript有很多种方式可以在html中包含文件

通常我们使用http请求从服务端获取数据,返回额数据我们可以通过使用innerHTML写入到html元素中。

 

angularJS包含

使用AngularJS,你可以使用ng-include指令来包含HTML内容:

<body ng-app=""> <div ng-include="‘runoob.htm‘"></div> </body>

 

包含AgularJS代码

ng-include指令除了可以包含HTML文档外,还可以包含AngularJS代码

sites.htm 文件代码:

<table> <tr ng-repeat="x in names"> <td>{{ x.Name }}</td> <td>{{ x.Url }}</td> </tr> </table>
 
包含的文件 "sites.htm" 中有 AngularJS 代码,它将被正常执行:

sites.htm 文件代码:

<div ng-app="myApp" ng-controller="sitesCtrl"> <div ng-include="‘sites.htm‘"></div> </div> <script> var app = angular.module(‘myApp‘, []); app.controller(‘sitesCtrl‘, function($scope, $http) { $http.get("sites.php").then(function (response) { $scope.names = response.data.records; }); }); </script>
 

跨域包含

默认情况下, ng-include 指令不允许包含其他域名的文件。

如果你需要包含其他域名的文件,你需要设置域名访问白名单:

 

<body ng-app="myApp"> <div ng-include="‘http://c.runoob.com/runoobtest/angular_include.php‘"></div> <script> var app = angular.module(‘myApp‘, []) app.config(function($sceDelegateProvider) { $sceDelegateProvider.resourceUrlWhitelist([ ‘http://c.runoob.com/runoobtest/**‘ ]); }); </script> </body>

 

angular.js包含

标签:module   response   ctr   asc   lis   访问   resource   http请求   example   

原文地址:http://www.cnblogs.com/lywh/p/6437859.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!