angularjs1- ng-include

Posted 672530440

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了angularjs1- ng-include相关的知识,希望对你有一定的参考价值。

<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="../angular.min.js"></script>
    <style>
        .red{ background:red;}
        .yellow{ background:yellow;}
    </style>
</head>
<body>
<div ng-app="myApp">
    <div ng-controller="firstController">
        <div ng-bind="text"></div>
         <div ng-include="url"></div>
    </div>
</div>
<script type="text/javascript">
    var app = angular.module(myApp,[]);
    app.controller(firstController,[$scope,$interval,function($scope,$interval){
        //$scope.text = ‘<h1>hello</h1>‘;
        $scope.text = hello;
        $scope.url = test.html;
    }]);
</script>
</body>
</html>
<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script type="text/javascript" src="../angular.min.js"></script>
    <style>
        .red{ background:red;}
        .yellow{ background:yellow;}
    </style>
</head>
<body>
<div ng-app="myApp">
    <div ng-controller="firstController">
        <div ng-bind="text"></div>
          <div ng-include="url"></div>
          <div ng-include="tpl"></div>
         <div ng-include src="tpl2"></div>
    </div>
    //以script方式引入模版
    <script type="text/ng-template" id="tpl.html">
        Content of the template.111111111111
    </script>
    <script type="text/ng-template" id="tpl2.html">
        Content of the template.2222222222
    </script>
</div>
<script type="text/javascript">
    var app = angular.module(myApp,[]);
    app.controller(firstController,[$scope,$interval,function($scope,$interval){
        //$scope.text = ‘<h1>hello</h1>‘;
        $scope.text = hello;

        $scope.url = test.html;

        $scope.tpl = tpl.html;
        $scope.tpl2 = tpl2.html;

    }]);
</script>

</body>
</html>

 

以上是关于angularjs1- ng-include的主要内容,如果未能解决你的问题,请参考以下文章

Ng-include页面嵌套

如何动态构建 ng-include src?

原 ng-include用法分析以及多标签页面的简单实现方式

如何在 ng-include 中嵌套 ng-view?

ng-show 不能与 ng-include 一起使用

ng-include 不适用于包含 javascript 的 html