使用AngularJS來(lái)實(shí)現(xiàn)HTML頁(yè)面嵌套的方法
HTML不支持嵌入在HTML頁(yè)面中的HTML頁(yè)面。實(shí)現(xiàn)這一功能通過(guò)使用以下方式:
- 使用Ajax - 讓一臺(tái)服務(wù)器來(lái)調(diào)用獲取相應(yīng)的HTML頁(yè)面,并將其設(shè)置在HTML控件的innerHTML。
- 使用服務(wù)器端包含 - JSP,PHP等Web端服務(wù)器技術(shù)可以在包括動(dòng)態(tài)頁(yè)面中的HTML頁(yè)面。
使用AngularJS,我們可以用ng-include指令在一個(gè)HTML頁(yè)面嵌入另一個(gè)HTML頁(yè)面。
<div ng-app="" ng-controller="studentController"> <div ng-include="'main.html'"></div> <div ng-include="'subjects.html'"></div> </div>
例子
tryAngularJS.html
<html>
<head>
<title>Angular JS Includes</title>
<style>
table, th , td {
border: 1px solid grey;
border-collapse: collapse;
padding: 5px;
}
table tr:nth-child(odd) {
background-color: #f2f2f2;
}
table tr:nth-child(even) {
background-color: #ffffff;
}
</style>
</head>
<body>
<h2>AngularJS Sample Application</h2>
<div ng-app="" ng-controller="studentController">
<div ng-include="'main.html'"></div>
<div ng-include="'subjects.html'"></div>
</div>
<script>
function studentController($scope) {
$scope.student = {
firstName: "Mahesh",
lastName: "Parashar",
fees:500,
subjects:[
{name:'Physics',marks:70},
{name:'Chemistry',marks:80},
{name:'Math',marks:65},
{name:'English',marks:75},
{name:'Hindi',marks:67}
],
fullName: function() {
var studentObject;
studentObject = $scope.student;
return studentObject.firstName + " " + studentObject.lastName;
}
};
}
</script>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.2.15/angular.min.js"></script>
</body>
</html>
main.html
<table border="0">
<tr><td>Enter first name:</td><td><input type="text" ng-model="student.firstName"></td></tr>
<tr><td>Enter last name: </td><td><input type="text" ng-model="student.lastName"></td></tr>
<tr><td>Name: </td><td>{{student.fullName()}}</td></tr>
</table>
subjects.html
<p>Subjects:</p>
<table>
<tr>
<th>Name</th>
<th>Marks</th>
</tr>
<tr ng-repeat="subject in student.subjects">
<td>{{ subject.name }}</td>
<td>{{ subject.marks }}</td>
</tr>
</table>
輸出
要運(yùn)行這個(gè)例子,需要部署textAngularJS.html,main.html和subjects.html 到一個(gè)網(wǎng)絡(luò)服務(wù)器。使用服務(wù)器URL在Web瀏覽器中打開textAngularJS.html。看到結(jié)果。

- Angular+Node生成隨機(jī)數(shù)的方法
- angularjs實(shí)現(xiàn)猜數(shù)字大小功能
- angularjs實(shí)現(xiàn)猜大小功能
- AngularJS實(shí)現(xiàn)元素顯示和隱藏的幾個(gè)案例
- AngularJS中的指令全面解析(必看)
- AngularJS中的模塊詳解
- AngularJs 彈出模態(tài)框(model)
- angularjs 處理多個(gè)異步請(qǐng)求方法匯總
- Angularjs制作簡(jiǎn)單的路由功能demo
- AngularJS實(shí)現(xiàn)表單驗(yàn)證
- AngularJS實(shí)現(xiàn)的生成隨機(jī)數(shù)與猜數(shù)字大小功能示例
相關(guān)文章
AngularJS實(shí)現(xiàn)進(jìn)度條功能示例
這篇文章主要介紹了AngularJS實(shí)現(xiàn)進(jìn)度條功能,結(jié)合具體完整實(shí)例形式分析了AngularJS實(shí)現(xiàn)進(jìn)度條功能的原理、相關(guān)知識(shí)點(diǎn)與注意事項(xiàng),需要的朋友可以參考下2017-07-07
深入探究AngularJS框架中Scope對(duì)象的超級(jí)教程
這篇文章主要介紹了AngularJS框架中Scope對(duì)象使用的相關(guān)學(xué)習(xí)教程,包括其和rootscope的區(qū)別介紹,需要的朋友可以參考下2016-01-01
Angular學(xué)習(xí)筆記之a(chǎn)ngular的$filter服務(wù)淺析
本文是小編記錄的angular學(xué)習(xí)筆記,通過(guò)本文首先給大家介紹了$filter服務(wù),然后介紹下內(nèi)置filter及filter的簡(jiǎn)單使用,非常不錯(cuò)具有參考借鑒價(jià)值,感興趣的朋友一起看看吧2016-11-11
Angularjs material 實(shí)現(xiàn)搜索框功能
這篇文章主要介紹了Angularjs material 實(shí)現(xiàn)搜索框功能的相關(guān)資料,需要的朋友可以參考下2016-03-03
詳解AngularJS中$http緩存以及處理多個(gè)$http請(qǐng)求的方法
$http 是 AngularJS 中的一個(gè)核心服務(wù),用于讀取遠(yuǎn)程服務(wù)器的數(shù)據(jù),通過(guò)本文給大家介紹AngularJS中$http緩存以及處理多個(gè)$http請(qǐng)求的方法,希望的朋友一起學(xué)習(xí)吧2016-02-02
體驗(yàn)jQuery和AngularJS的不同點(diǎn)及AngularJS的迷人之處
AngualrJS是一個(gè)很貼心的web應(yīng)用框架,本篇通過(guò)jQuery和Angular兩種方式來(lái)實(shí)現(xiàn)同一個(gè)實(shí)例,從而體驗(yàn)兩者的不同點(diǎn)以及AngularJS的迷人之處2016-02-02

