ng包含不'ng应用程序获得名称时不起作用
ng-include doesn't work when ng-app gets a name
我正在使用ng-include来包含导航条。与ng app="组合使用效果良好。但当我使用一个名称(例如,ng-app="myApp")时,它就不再起作用了。请参见示例。
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body >
<div ng-app="">
<div ng-include="'pages/navbar.html'"></div>
<script src="app.js"</script>
</div>
</body>
</html>
app.js
var app = angular.module('myApp', []);
app.controller('mainController', function($scope) {
});
上面的操作很好,但当我插入名称"myApp"时,它停止包括导航栏。
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body >
<div ng-app="myApp">
<div ng-include="'pages/navbar.html'"></div>
<script src="app.js"</script>
</div>
</body>
</html>
为什么
您在这里有一个打字错误
<script src="app.js"</script>
应该是
<script src="app.js"></script>
只要它在angular.js之后加载,那么你的应用程序就应该能够找到myApp模块的声明(你已经要求它使用ng-app="myApp"
在浏览器控制台中检查是否有任何错误-如果没有加载脚本,您将看到类似cannot find module
的错误
我相信您已经错过了以正确的样式包含app.js
文件。控制台里有错误吗?
已编辑
<!DOCTYPE html>
<html>
<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.4.8/angular.min.js"></script>
<body >
<div ng-app="myApp">
<div ng-include="'pages/navbar.html'"></div>
</div>
<script src="app.js"></script>
</body>
</html>
相关文章:
- 角度ng变化或ng点击选择can'不起作用
- AngularJS ng include dons'不起作用
- ng disabled在chrome中不起作用.按钮在角度上未禁用
- 角度无线电按钮ng模型不起作用
- Angular js+ng repeat+字母数字索引不起作用
- 角度Js ng-disabled不起作用
- AngularJS ng include won'不知什么原因不起作用
- 角度过滤器和ng点击不起作用
- 初始化ng模型时,Angular ui选择占位符不起作用
- 角度去抖动(ng模型选项)不起作用
- angularjs ng点击运行时标记不起作用
- Ng点击don´不起作用
- 为什么ng节目不起作用
- 带有粘性标题的角度ng视图不起作用
- select中布尔值的Angularjs ng值不起作用
- ng模型在$(element).clone()之后不起作用
- AngularJS触发ng更改不起作用
- Angular js-ng选项不起作用
- Angular JS中的setInterval对HighCharts-ng不起作用
- 禁用Angular js ng不起作用