-
Notifications
You must be signed in to change notification settings - Fork 19
Expand file tree
/
Copy pathangularjs_nginclude3.html
More file actions
70 lines (68 loc) · 2.64 KB
/
angularjs_nginclude3.html
File metadata and controls
70 lines (68 loc) · 2.64 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>AngularJS·Hello AngularJS</title>
<link rel="stylesheet" href="http://cdn.bootcss.com/bootstrap/3.3.2/css/bootstrap.css">
<style>
.demo{
margin-bottom:10px;
border-bottom:1px solid #1b926c;
}
</style>
</head>
<body ng-app="MyAPP">
<div class="container">
<div class="row">
<nav class="navbar navbar-default navbar-static-top">
<div class="container-fluid">
<div class="navbar-header">
<a class="navbar-brand" href="../index.html">首页</a>
</div>
<ul class="nav navbar-nav">
<li class="active"><a href="javascript:void(0)">Link</a></li>
<li><a href="javascript:void(0)">Link2</a></li>
</ul>
</div>
</nav>
</div>
<h3>ng-include示例</h3>
<div class="row text-center demo" ng-controller="MyController">
<div ng-include src="'tpl_header.html'"></div>
<article style="min-height:300px;padding:20px;">
如果你是一个angular的开发者的话,对于ng-html2js你应该 很熟悉。对于angular的指令,我们经常需要定义模板( directive template/templateUrl),你可以选择讲html page 放在真正的的web容器中寄宿,也可以选择angular的ng-template 放在view的page之上,抑或也可以讲html打成一个js文件和directive 的js文件合并在一起发布。
</article>
<div ng-include src="'tpl_footer.html'"></div>
</div>
</div>
</div>
</body>
</html>
<script src="http://cdn.bootcss.com/angular.js/1.3.8/angular.js" type="text/javascript"></script>
<script type="text/ng-template" id="tpl_header.html">
<header class="row" style="padding:10px;background:darkolivegreen;">
<h3>{{headerTitle}}</h3>
<p><input type="text" ng-model="name"></p>
<p>{{name}}</p>
<button ng-click="show()">点我</button>
</header>
</script>
<script type="text/ng-template" id="tpl_footer.html">
<footer class="row" style="padding:30px;background:#999;color:red;">
<h2>{{footerTitle}}</h2>
<p><input type="text" ng-model="name"></p>
<p>{{name}}</p>
<button ng-click="show()">点我</button>
</footer>
</script>
<script>
var app=angular.module("MyAPP",[]);
app.controller("MyController",function($scope){
$scope.headerTitle="我是网页顶部标题";
$scope.footerTitle="我是页脚标题";
$scope.name="hello";
$scope.show=function(){
alert($scope.name);
}
});
</script>