AngularJS mengandung
Dalam AngularJS, Anda dapat menyertakan file HTML di HTML.
Ini berisi file HTML di HTML
Dalam HTML, ini tidak didukung oleh file HTML yang berisi fungsi.
Layanan Side Termasuk
Kebanyakan fitur dukungan server-side scripting menyertakan file (SSI: Server Side Termasuk).
Menggunakan SSI, Anda dapat dimasukkan dalam file HTML dalam HTML dikirim ke browser klien.
Contoh PHP
<? Php require ( "navigation.php" );?>
client berisi
Ada banyak cara dengan JavaScript dapat berisi file HTML dalam HTML.
Biasanya kita menggunakan permintaan http (AJAX) untuk mendapatkan data dari server, kita dapat menulis data yang dikembalikan dengan menggunakan innerHTML untuk elemen HTML.
AngularJS mengandung
Gunakan AngularJS, Anda dapat menggunakan ng-termasuk direktif untuk menyertakan konten HTML:
contoh
<Body>
<Class Div = "container">
<Div ng-termasuk = " ' myUsers_List.htm'"> </ div>
<Div ng-termasuk = " ' myUsers_Form.htm'"> </ div>
</ Div>
</ Body>
<Class Div = "container">
<Div ng-termasuk = " ' myUsers_List.htm'"> </ div>
<Div ng-termasuk = " ' myUsers_Form.htm'"> </ div>
</ Div>
</ Body>
Lanjutkan sebagai berikut:
Langkah 1: Buat daftar HTML
myUsers_List.html
<H3> Pengguna </ h3>
<Table class = "tabel tabel- belang">
<Thead> <tr>
<Th> Edit </ th>
<Th> Nama Pertama </ th >
<Th> Nama terakhir </ th >
</ Tr> </ thead>
<Tbody> <tr ng-repeat = "pengguna dalam pengguna">
<Td>
<Button kelas = "btn" ng -klik = "EditUser (user.id)">
<Span class = "glyphicon glyphicon- pensil"> </ span> & nbsp; & nbsp; Sunting
</ Tombol>
</ Td>
<Td> {{user.fName}} </ td>
<Td> {{user.lName}} </ td>
</ Tr> </ tbody>
</ Table>
<Table class = "tabel tabel- belang">
<Thead> <tr>
<Th> Edit </ th>
<Th> Nama Pertama </ th >
<Th> Nama terakhir </ th >
</ Tr> </ thead>
<Tbody> <tr ng-repeat = "pengguna dalam pengguna">
<Td>
<Button kelas = "btn" ng -klik = "EditUser (user.id)">
<Span class = "glyphicon glyphicon- pensil"> </ span> & nbsp; & nbsp; Sunting
</ Tombol>
</ Td>
<Td> {{user.fName}} </ td>
<Td> {{user.lName}} </ td>
</ Tr> </ tbody>
</ Table>
Coba »
Langkah 2: Buat bentuk HTML
myUsers_Form.html
<Button kelas = "btn btn- sukses" ng-klik = "EditUser ( 'baru')">
<Span class = "glyphicon glyphicon- pengguna"> </ span> Create New Pengguna
</ Tombol>
<Hr>
<H3 ng-show = "edit "> Create New Pengguna: </ h3>
<H3 ng-hide = "edit "> Edit Pengguna: </ h3>
<Kelas Formulir = "bentuk-horisontal ">
<Class Div = "bentuk-kelompok ">
<Class Label = "col-sm -2 kontrol label"> Nama Pertama: </ label>
<Div class = "col-sm -10">
<Input type = "text" ng -Model = "fname" ng-disabled = "! Edit" placeholder = "Nama Depan">
</ Div>
</ Div>
<Class Div = "bentuk-kelompok ">
<Label class = "col-sm -2 kontrol label"> Nama terakhir: </ label>
<Div class = "col-sm -10">
<Input type = "text" ng -Model = "lname" ng-disabled = "! Edit" placeholder = "Nama terakhir">
</ Div>
</ Div>
<Class Div = "bentuk-kelompok ">
<Label class = "col-sm -2 kontrol label"> Password: </ label>
<Div class = "col-sm -10">
<Input type = "password" ng -Model = "passw1" placeholder = "Password">
</ Div>
</ Div>
<Class Div = "bentuk-kelompok ">
<Label class = "col-sm -2 kontrol label"> Ulangi: </ label>
<Div class = "col-sm -10">
<Input type = "password" ng -Model = "passw2" placeholder = "Ulangi Password">
</ Div>
</ Div>
</ Form>
<Hr>
<Button kelas = "btn btn- sukses" = "error || lengkap" ng-orang cacat>
<Span class = "glyphicon glyphicon- menyimpan"> </ span> Simpan Perubahan
</ Tombol>
<Span class = "glyphicon glyphicon- pengguna"> </ span> Create New Pengguna
</ Tombol>
<Hr>
<H3 ng-show = "edit "> Create New Pengguna: </ h3>
<H3 ng-hide = "edit "> Edit Pengguna: </ h3>
<Kelas Formulir = "bentuk-horisontal ">
<Class Div = "bentuk-kelompok ">
<Class Label = "col-sm -2 kontrol label"> Nama Pertama: </ label>
<Div class = "col-sm -10">
<Input type = "text" ng -Model = "fname" ng-disabled = "! Edit" placeholder = "Nama Depan">
</ Div>
</ Div>
<Class Div = "bentuk-kelompok ">
<Label class = "col-sm -2 kontrol label"> Nama terakhir: </ label>
<Div class = "col-sm -10">
<Input type = "text" ng -Model = "lname" ng-disabled = "! Edit" placeholder = "Nama terakhir">
</ Div>
</ Div>
<Class Div = "bentuk-kelompok ">
<Label class = "col-sm -2 kontrol label"> Password: </ label>
<Div class = "col-sm -10">
<Input type = "password" ng -Model = "passw1" placeholder = "Password">
</ Div>
</ Div>
<Class Div = "bentuk-kelompok ">
<Label class = "col-sm -2 kontrol label"> Ulangi: </ label>
<Div class = "col-sm -10">
<Input type = "password" ng -Model = "passw2" placeholder = "Ulangi Password">
</ Div>
</ Div>
</ Form>
<Hr>
<Button kelas = "btn btn- sukses" = "error || lengkap" ng-orang cacat>
<Span class = "glyphicon glyphicon- menyimpan"> </ span> Simpan Perubahan
</ Tombol>
Coba »
Langkah 3: Buat Pengendali
myUsers.js
angular.module( 'myApp' , []).controller( 'userCtrl' , function ($scope) {
$scope.fName = '' ;
$scope.lName = '' ;
$scope.passw1 = '' ;
$scope.passw2 = '' ;
$scope.users = [
{id: 1 , fName: 'Hege' ,lName: "Pege" },
{id: 2 , fName: 'Kim' ,lName: "Pim" },
{id: 3 , fName: 'Sal' ,lName: "Smith" },
{id: 4 , fName: 'Jack' ,lName: "Jones" },
{id: 5 , fName: 'John' ,lName: "Doe" },
{id: 6 , fName: 'Peter' ,lName: "Pan" }
];
$scope.edit = true ;
$scope.error = false ;
$scope.incomplete = false ;
$scope.editUser = function (id) {
if (id == 'new' ) {
$scope.edit = true ;
$scope.incomplete = true ;
$scope.fName = '' ;
$scope.lName = '' ;
} else {
$scope.edit = false ;
$scope.fName = $scope.users[id-1].fName;
$scope.lName = $scope.users[id-1].lName;
}
};
$scope.$watch( 'passw1' , function () {$scope.test();});
$scope.$watch( 'passw2' , function () {$scope.test();});
$scope.$watch( 'fName' , function () {$scope.test();});
$scope.$watch( 'lName' , function () {$scope.test();});
$scope.test = function () {
if ($scope.passw1 !== $scope.passw2) {
$scope.error = true ;
} else {
$scope.error = false ;
}
$scope.incomplete = false ;
if ($scope.edit && (!$scope.fName.length ||
!$scope.lName.length ||
!$scope.passw1.length || !$scope.passw2.length)) {
$scope.incomplete = true ;
}
};
})
$scope.fName = '' ;
$scope.lName = '' ;
$scope.passw1 = '' ;
$scope.passw2 = '' ;
$scope.users = [
{id: 1 , fName: 'Hege' ,lName: "Pege" },
{id: 2 , fName: 'Kim' ,lName: "Pim" },
{id: 3 , fName: 'Sal' ,lName: "Smith" },
{id: 4 , fName: 'Jack' ,lName: "Jones" },
{id: 5 , fName: 'John' ,lName: "Doe" },
{id: 6 , fName: 'Peter' ,lName: "Pan" }
];
$scope.edit = true ;
$scope.error = false ;
$scope.incomplete = false ;
$scope.editUser = function (id) {
if (id == 'new' ) {
$scope.edit = true ;
$scope.incomplete = true ;
$scope.fName = '' ;
$scope.lName = '' ;
} else {
$scope.edit = false ;
$scope.fName = $scope.users[id-1].fName;
$scope.lName = $scope.users[id-1].lName;
}
};
$scope.$watch( 'passw1' , function () {$scope.test();});
$scope.$watch( 'passw2' , function () {$scope.test();});
$scope.$watch( 'fName' , function () {$scope.test();});
$scope.$watch( 'lName' , function () {$scope.test();});
$scope.test = function () {
if ($scope.passw1 !== $scope.passw2) {
$scope.error = true ;
} else {
$scope.error = false ;
}
$scope.incomplete = false ;
if ($scope.edit && (!$scope.fName.length ||
!$scope.lName.length ||
!$scope.passw1.length || !$scope.passw2.length)) {
$scope.incomplete = true ;
}
};
})
Langkah 4: Buat Homepage a
myUsers.html
<! DOCTYPE html>
<Html>
<Link rel = "stylesheet" href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<Script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </ script>
<Tubuh ng-app = "myApp " ng-controller = "userCtrl">
<Class Div = "container">
<Div ng-termasuk = " ' myUsers_List.htm'"> </ div>
<Div ng-termasuk = " ' myUsers_Form.htm'"> </ div>
</ Div>
<Script src = "myUsers.js"> </ script>
</ Body>
</ Html>
<Html>
<Link rel = "stylesheet" href = "http://maxcdn.bootstrapcdn.com/bootstrap/3.2.0/css/bootstrap.min.css">
<Script src = "http://ajax.googleapis.com/ajax/libs/angularjs/1.3.14/angular.min.js"> </ script>
<Tubuh ng-app = "myApp " ng-controller = "userCtrl">
<Class Div = "container">
<Div ng-termasuk = " ' myUsers_List.htm'"> </ div>
<Div ng-termasuk = " ' myUsers_Form.htm'"> </ div>
</ Div>
<Script src = "myUsers.js"> </ script>
</ Body>
</ Html>
Coba »