Introduction
HTML does not support embedding HTML pages within HTML. To do so, you have to use AngularJS Include Directives. The ng-controller directive can be used to embed an html page within HTML.
Syntax:
<element ng-include=" "> content <element> |
You can use AngularJS ng-include directive to include HTML from another file.
Syntax:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body ng-app="">
<div ng-include="'HTMLFileName'"></div>
</body>
</html>
Include AngularJS Code
The HTML files that you include using the ng-include directive can also contain the angular js code.
Ninjas.html file:
<table>
<tr ng-repeat="x in names">
<td>{{ x.Name }}</td>
<td>{{ x.Place }}</td>
</tr>
</table>
Include the above "Ninjas.html" in your web page, and all AngularJS code, including that inside the included file, will be executed.
Example:
<!DOCTYPE html>
<html>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.9/angular.min.js"></script>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
<div ng-include="'myTable.htm'"></div>
</div>
<script>
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope, $http) {
$http.get("customers.php").then(function (response) {
$scope.names = response.data.records;
});
});
</script>
<p>A paragraph.</p>
</body>
</html>