Angula Includes
AngularJS Includes
With AngularJS, you lot tin sack include HTML from an external file.
AngularJS Includes
With AngularJS, you lot tin sack include HTML content using the ng-include directive:Example
<body ng-app="">
<div ng-include="'myFile.htm'"></div>
</body>
Include AngularJS Code
The HTML files you lot include amongst the ng-include directive, tin sack equally good comprise AngularJS code:myTable.htm:
<table>
<tr ng-repeat="x inwards names">
<td>{{ x.Name }}</td>
<td>{{ x.Country }}</td>
</tr>
</table>
Example
<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>
Include Cross Domains
By default, the ng-include directive does non permit you lot to include files from other domains.To include files from around other domain, you lot tin sack add together a whitelist of legal files and/or domains inwards the config business office of your application:
Example:
<body ng-app="myApp">
<div ng-include="'https://tryit.w3schools.com/angular_include.php'"></div>
<script> var app = angular.module('myApp', [])
app.config(function($sceDelegateProvider) {
$sceDelegateProvider.resourceUrlWhitelist([
'https://tryit.w3schools.com/**'
]);
});
</script>
</body>
Be certain that the server on the goal allows cross domain file access.
Comments
Post a Comment