0
加載包含AngularJS代碼的HTML文件時遇到問題!jQuery.load包含AngularJS的HTML
這裏是我的代碼片段:
page1.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<script src="jquery-2.2.4.min.js"></script>
</head>
<body>
<div id="content">
</div>
<script>
$(document).ready(function() {
$('#content').load('page2.html#body');
});
</script>
</body>
</html>
page2.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"></meta>
<meta name="viewport" content="width=device-width, initial-scale=1"></meta>
<script src="angular.min.js"></script>
</head>
<body>
<div ng-app="myApp" ng-controller="customersCtrl">
{{ value }}
</div>
<script>
//<![CDATA[
var app = angular.module('myApp', []);
app.controller('customersCtrl', function($scope) {
$scope.value = "hello world!";
});
//]]>
</script>
</body>
</html>
第2頁單獨的作品就好了!但是,當我嘗試加載它裏面第1頁,我收到以下錯誤信息:
Uncaught Error: [$injector:modulerr] http://errors.angularjs.org/1.4.8/ $injector/modulerr?p0=myApp&p1=Error%3A%2… at HTMLDocument.eval (eval at globalEval (jquery-2.2.4.min.js:2), :294:192) at i (jquery-2.2.4.min.js:2)
添加jquery後,它的工作!但我現在很困惑,當我單獨加載page2時,它沒有顯式導入jquery.js,任何人都可以解釋爲什麼嗎?只是好奇 –