ng-include 指令除了可以包含 HTML 文件外,还可以包含 AngularJS 代码

2017-07-12 18:40:00
admin
原创
546
<!DOCTYPE html>
<html>
<meta charset="utf-8">
<script src="https://cdn.bootcss.com/angular.js/1.4.6/angular.min.js"></script>
<body>

<div ng-app="myApp" ng-controller="sitesCtrl"> 
  <div ng-include="'http://code.ybao.org/demo/src/sites.htm'"></div>
</div>
 
<script>
var app = angular.module('myApp', []);
app.controller('sitesCtrl', function($scope, $http) {
    $http.get("http://code.ybao.org/demo/src/sites.php").then(function (response) {
        $scope.names = response.data.records;
    });
});
</script>

<p>AngularJS 代码包含在 "sites.htm" 文件中。</p>

</body>
</html>
  • QQ讨论群
  • 关注微信
    • 欢迎咨询
    • 欢迎加入QQ群 16506021
  • 公众号:源宝网络