AngularJS Include
In AngularJS, you can include HTML files in HTML.
Include HTML Files in HTML
In HTML, including HTML files is not supported yet.
Server-side Includes
Most server-side scripts support the include file functionality (SSI: Server Side Includes)。
Using SSI, you can include HTML files in HTML and send them to the client browser.
PHP Example
Client-side Includes
There are many ways to include HTML files in HTML through JavaScript.
Usually we use HTTP requests (AJAX) to get data from the server, we can use the returned datainnerHTMLto write into HTML elements.
AngularJS Includes
Using AngularJS, you can useng-includethe directive to include HTML content:
The steps are as follows:
example.htm file code:
Include AngularJS code
In addition to including HTML files, the ng-include directive can also include AngularJS code:
sites.htm file code:
The included file "sites.php" contains AngularJS code, which will be executed normally:
Example
Try it Yourself »
Cross-domain Includes
By default, the ng-include directive does not allow including files from other domains.
If you need to include files from other domains, you need to set a domain access whitelist:
sites.htm file code:
Try it Yourself »
In addition, you also need to configure the server to allow cross-domain access. For the configuration method, refer to:The best solution to PHP Ajax cross-domain issues.