Include ng AngularJS

Mga rekomendasyon ng kurso:

Include ng AngularJS

Ginagamit ng AngularJS, maaari mong kasama ang HTML mula sa panlabas na file. ng-include Instruction na kasama ang HTML content:

Instance

<body ng-app="">
<div ng-include="'myFile.htm'"></div>
</body>

Subukan Ngayon

Kasama ang code ng AngularJS

Ang HTML file na iyong kasama gamit ang instruction na ng-include ay maaari ring magkaroon ng code ng AngularJS:

myTable.htm:
<table>
  <tr ng-repeat="x in names">
    <td>{{ x.Name }}</td>
    <td>{{ x.Country }}</td>
  </tr>
</table>

Kasama sa iyong webpage ang file na "myTable.htm", ang lahat ng code ng AngularJS ay magsasauli, kahit sa mga code na nasa na kasama sa file:

Instance

<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>

Subukan Ngayon

Transdomain Inclusion

Sa normal na kaso, ang instruction na ng-include ay hindi nagpapahintulot na kasama ang mga file mula sa ibang domain.

Para kasama ang mga file mula sa ibang domain, maaari mong idagdag ang mga legal na file at/o mga domain sa white list sa function ng config ng application:

Instance

<body ng-app="myApp">
<div ng-include="'https://tryit.codew3c.com/angular_include.php'"></div>
<script>
var app = angular.module('myApp', [])
app.config(function($sceDelegateProvider) {
  $sceDelegateProvider.resourceUrlWhitelist([
    'https://tryit.codew3c.com/**'
  ]);
});
</script>
</body>

Subukan Ngayon

Tiyakin na ang target server ay pinapayagan ang pag-access ng file sa cross-domain.