Angularjs contains
In Angularjs, you can include HTML files in HTML.
Include HTML files in HTML
In HTML, the ability to include HTML files is not currently supported.
The service side contains
Most server-side scripts support the Include file feature (Ssi:server Side Includes).
With SSI, you can include HTML files in HTML and send them to the client browser.
PHP instance
<?php require ("navigation.php");?>
Client contains
There are a number of ways to include HTML files in HTML through JavaScript.
Typically we use HTTP request (AJAX) to get data from the server, and the returned data can be written to HTML elements by using InnerHTML.
Angularjs contains
With Angularjs, you can use the Ng-include directive to include HTML content:
Instance
<body>
<div class= "container" >
<div ng-include= "' myusers_list.htm '" ></div>
<div ng-include= "' myusers_form.htm '" ></div>
</div>
The steps are as follows:
Step 1: Create an HTML list
Myusers_list.html
Run Result:
User
Edit |
name |
Last Name |
Edit |
{{User.fname}}} |
{{User.lname}}} |
Step 2: Create an HTML form
Myusers_form.html
<button class= "btn btn-success ng-click=" Edituser (' new ') "> <span class=" Glyphicon glyphicon-user "></ Span> Create a new user </button>
Run Result:
Step 3: Create the Controller
Myusers.js
Angular.module (' myApp ', []). Controller (' Userctrl ', function ($scope) {$scope. fName = '; $scope. LName = '; $scope. PASSW
1 = ';
$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;
}
}; })
Step 4: Create a home page
Myusers.html
Run Result:
The above is to angularjs contain the material collation, hope can help Angularjs programming friend.