Angularjs Study Chapter (20)

Source: Internet
Author: User

AngularJSinclude

In AngularJS, you can include HTML files in HTML.

With AngularJS, you can use the ng-include directive to include HTML content:

<ng-app= ""><ng-include= "' Test.htm ' "></div></body>
Test.htm File Code:
< H1 > Rookie Tutorials </H1><p> This is a contained HTML page that uses Ng-include instructions to achieve! </ P >

The ng-include directive can contain AngularJS code in addition to HTML files:

<!DOCTYPE HTML><HTML><MetaCharSet= "Utf-8"><Scriptsrc= "Http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></Script><Body><DivNg-app= "MYAPP"Ng-controller= "Sitesctrl">   <DivNg-include= "' sites.htm '"></Div></Div> <Script>varapp=Angular.module ('myApp', []); App.controller ('Sitesctrl', function($scope, $http) {$http. Get ("sites.php"). Then (function(response) {$scope. Names=response.data.records; });});</Script><P>The AngularJS code is included in the "sites.htm" file.</P></Body></HTML>
Sites.htm File Code:
<Table><TRng-repeat= "x in Names"><TD>{{X.name}}</TD><TD>{{X.url}}</TD></TR></Table>
Cross-domain Containment

By default, the Ng-include directive does not allow files that contain other domain names.

If you need to include a file with another domain name, you need to set the domain name Access Whitelist:

<!DOCTYPE HTML><HTML><MetaCharSet= "Utf-8"><Scriptsrc= "Http://cdn.static.runoob.com/libs/angular.js/1.4.6/angular.min.js"></Script><BodyNg-app= "MYAPP"> <DivNg-include= "' http://c.runoob.com/runoobtest/angular_include.php '"></Div> <Script>varapp=Angular.module ('myApp', []) app. Config (function($sceDelegateProvider) {$sceDelegateProvider. resourceurlwhitelist (['http://c.runoob.com/runoobtest/**'    ]);});</Script><P>You need to set the server side to allow cross-domain access, and the Setup method can refer to<aTarget= "_blank"href= "/w3cnote/php-ajax-cross-border.html">PHP Ajax the best solution for cross-domain problems</a>. </Body></HTML>

In addition, you need to set the server side to allow cross-domain access, the setting method can be consulted: PHP Ajax cross-domain problem best solution.

<? php//allows all domains to access the header (' access-control-allow-origin:* '), Echo ' <b style= ' color:red ' > I am a cross-domain content </b> '; ?>

Angularjs Study Chapter (20)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.