Home Web Front-end HTML Tutorial (10) Reasons and solutions for the failure of the ng-inlude directive to load the page_html/css_WEB-ITnose

(10) Reasons and solutions for the failure of the ng-inlude directive to load the page_html/css_WEB-ITnose

Jun 24, 2016 am 11:49 AM

The ng-include directive provided in angularjs is very similar to the in JSP. It is used to merge multiple child pages into the same parent page to avoid the parent page being too large and having poor readability. , difficult to maintain.

The parent page parent.html code is as follows:

<html>  <head>    <script src="angular-1.2.2/angular.js"></script>	<script>	 function rootController($scope,$rootScope,$injector)	 {		$rootScope.name = "aty";		$rootScope.age = 25;	 }	</script>  </head>  <body  ng-app ng-controller="rootController">        <h1>Hello, {{name}}!</h1>        <h1>Hello, {{age}}!</h1>		<div id="included" ng-include="'child.html'">            <input type="button" value="2"/>        </div>  </body></html>
Copy after login

The included child page child.html code is as follows:

 <div>        <h1>included, {{name}}!</h1>        <h1>included, {{age}}!</h1> </div>
Copy after login


I use IE11 and Chrome39 runs parent.html and finds that the child.html page cannot be included in parent.html. The error message reported under IE is as follows:

Error: 拒绝访问。   at Anonymous function (file:///D:/learn/angular-1.2.2/angular.js:7852:7)   at sendReq (file:///D:/learn/angular-1.2.2/angular.js:7720:9)   at serverRequest (file:///D:/learn/angular-1.2.2/angular.js:7454:9)
Copy after login

The error message reported under chrome is as follows:

XMLHttpRequest cannot load file:///D:/learn/include.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///D:/learn/include.html'.
Copy after login


The prompt under IE is a bit obscure, but the chrome prompt is obvious: cross-domain access is not allowed . From the above error message, you can see that when using the ng-include directive, AJAX request XMLHttpRequest will be used. However, we opened parent.html directly with the browser and did not access it through the web container, so there was a cross-domain access problem, and loading child.html failed. The solution is simple: deploy the code to a web container such as tomcat and access it through http.


When I usually practice javascript or JS framework, I use relatively lightweight tools. I don’t use IDEs like Eclipse. I usually use Notepad writes js code. Notepad can easily call the browser installed on the machine. Instructions like ng-include must be supported by the web container. You can use the front-end development artifact webstorm. When this tool runs HTML, it will automatically start the built-in web container, so that the ng-include instruction will not report an error.


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
1 months ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

What is the purpose of the <progress> element? What is the purpose of the <progress> element? Mar 21, 2025 pm 12:34 PM

The article discusses the HTML &lt;progress&gt; element, its purpose, styling, and differences from the &lt;meter&gt; element. The main focus is on using &lt;progress&gt; for task completion and &lt;meter&gt; for stati

What is the purpose of the <datalist> element? What is the purpose of the <datalist> element? Mar 21, 2025 pm 12:33 PM

The article discusses the HTML &lt;datalist&gt; element, which enhances forms by providing autocomplete suggestions, improving user experience and reducing errors.Character count: 159

What are the best practices for cross-browser compatibility in HTML5? What are the best practices for cross-browser compatibility in HTML5? Mar 17, 2025 pm 12:20 PM

Article discusses best practices for ensuring HTML5 cross-browser compatibility, focusing on feature detection, progressive enhancement, and testing methods.

What is the purpose of the <meter> element? What is the purpose of the <meter> element? Mar 21, 2025 pm 12:35 PM

The article discusses the HTML &lt;meter&gt; element, used for displaying scalar or fractional values within a range, and its common applications in web development. It differentiates &lt;meter&gt; from &lt;progress&gt; and ex

How do I use HTML5 form validation attributes to validate user input? How do I use HTML5 form validation attributes to validate user input? Mar 17, 2025 pm 12:27 PM

The article discusses using HTML5 form validation attributes like required, pattern, min, max, and length limits to validate user input directly in the browser.

What is the viewport meta tag? Why is it important for responsive design? What is the viewport meta tag? Why is it important for responsive design? Mar 20, 2025 pm 05:56 PM

The article discusses the viewport meta tag, essential for responsive web design on mobile devices. It explains how proper use ensures optimal content scaling and user interaction, while misuse can lead to design and accessibility issues.

What is the purpose of the <iframe> tag? What are the security considerations when using it? What is the purpose of the <iframe> tag? What are the security considerations when using it? Mar 20, 2025 pm 06:05 PM

The article discusses the &lt;iframe&gt; tag's purpose in embedding external content into webpages, its common uses, security risks, and alternatives like object tags and APIs.

Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Gitee Pages static website deployment failed: How to troubleshoot and resolve single file 404 errors? Apr 04, 2025 pm 11:54 PM

GiteePages static website deployment failed: 404 error troubleshooting and resolution when using Gitee...

See all articles