1-8.Angular-ng-include

Angular-ng-include

1.ng-style
2.ng-include

  • 在开发过程中,有时候需要把一个模块单独写到一个页面中,以便复用.
    使用原生html没有办法达到这种要求,一般都是通过服务器来完成此功能.我们可以使用angular当中的指令 ng-include来完成.
    ng-include 它的本质是发送一个ajax请求, 把请求结果, 放入对应标签里边.

<body ng-app="app" ng-controller="xmgController">

<!--1.ng-style它的值,是模型当中的值-->
<!--<p ng-style="sty">我是style</p>-->

<!--
2.ng-include

在html当中是没有办法直接引入其它文件。
浏览器不允许html对文件进行操作。
原因:出于安全考虑。

 原理:
    其实是发送了一个ajax请求。
    把请求的结果,插入到dom当中。

-->
<div ng-include="'08-head.html'"></div>
<div>主题</div>
<div ng-include="'08-foot.html'"></div>


</body>

<script src="js/angular.js"></script>
<script>
    //1.创建模块
    var app = angular.module('app', []);
    //2.创建控制器
    app.controller('xmgController', ['$scope', function ($scope) {
        $scope.sty = {
            "font-size" : "100px",
            "color" : "blue"
        };

    }]);

    //3.绑定模块 ng-app="app"
    //4.绑定控制器 ng-controller="xmgController"

</script>

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容