接手的之前的项目。一个左右分栏的效果,在index.html里面,通过load 方法 载入各个分页面。
现在我想在其中一个子页面里使用angular,在初始化模块的时候angular总是报错找不到入口模块。各位大神能不能帮我找下原因?
分页面代码
<html>
<body class="wysihtml5-supported">
<section class="content-header" ng-app="myApp">
<h1 ng-controller="Aaa">
{{name}}
<small></small>
</h1>
</section>
<script src="angular.js"></script>
<script>
angular.module("myApp",[]).controller("Aaa",['$scope',function($scope){
$scope.name = "出来好吧";
}])
</script>
</body>
</html>
报错信息如下
页面如下
求助怎么才能在这种情况下使用angular?
天蓬老师2017-04-10 17:16:22
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
<link rel="stylesheet" href="app.css">
</head>
<body>
<p>用户信息</p>
<p id="angular-content"></p>
<script src="jquery.js"></script>
<script src="angular.js"></script>
<script>
var $container = $('#angular-content');
$container.load('/angular/load.html', function () {
angular.module("myApp",[]).controller("Aaa",['$scope',function($scope){
$scope.name = "出来好吧";
}]);
angular.bootstrap($container,['myApp'])
});
</script>
</body>
</html>
<section class="content-header">
<h1 ng-controller="Aaa">
{{name}}
<small></small>
</h1>
</section>
你load的页面不要加什么html、body标签,没有意义的。这里采用动态加载的方式,把相应的js放在主页面里。
PHP中文网2017-04-10 17:16:22
<html>
<body class="wysihtml5-supported">
<section class="content-header" ng-app="myApp">
<h1 ng-controller="Aaa">
{{name}}
<small></small>
</h1>
</section>
<script src="angular.js"></script>
<script>
angular.module("myApp",[]).controller("Aaa",function($scope){
$scope.name = "出来好吧";
})
</script>
</body>
阿神2017-04-10 17:16:22
把两个<script></script>标签放在<head></head>里试试。写法上好像没什么问题,但是错误确实说的是你没声明myApp模块。