我需要一些帮助。只是必须学习角度,我就是这样设置我的。
这是我的文件结构。
AboutController.js
function AboutController( $scope ){
$scope.data = {
"data" : {
"name" : "nameku",
"email" : "email.com"
},
"data" : {
"name" : "nameku2",
"email" : "email2.com"
}
}
}
about.html
<script type="text/javascript" src="controllers/AboutController.js"></script>
<div ng-controller="AboutController">
<ul ng-repeat="d in data">
<li>{{d.name}}</li>
</ul>
</div>
的index.html
<html ng-app="TestingAngular">
<head>
<title>TestingAngular Dashboard</title>
</head>
<script type="text/javascript" src="components/angular/angular.min.js"></script>
<script type="text/javascript" src="components/angular-route/angular-route.min.js"></script>
<script type="text/javascript" src="route.js"></script>
<body>
<div ng-view></div>
</body>
</html>
route.js
angular.module('TestingAngular', ['ngRoute'])
.config( function( $routeProvider ){
$routeProvider
.when(
'/about' , {templateUrl: 'views/about.html'}
)
.when(
'/contact' , {templateUrl: 'views/contact.html'}
)
.when(
'/' , {templateUrl: 'views/home.html'}
);
});
我的问题是我收到此错误。是否有一种方式,我想要的方式可以工作?
当我移动
时 <script type="text/javascript" src="controllers/AboutController.js"></script>
在索引中,它会起作用。如果我的路径错误,请纠正我
错误:[ng:areq] http://errors.angularjs.org/1.2.25/ng/areq?p0=AboutController&p1=not%20aNaNunction%2C%20got%20undefined 在错误(本机)
答案 0 :(得分:3)
AngularJS需要在应用程序运行之前在config
阶段注册所有控制器,服务,指令和过滤器。开箱即用不支持延迟加载。因此,所有脚本都必须在索引页面中注册,所以你做得很好。
对于延迟加载,您需要查看一些这样的自定义组件 https://github.com/ocombe/ocLazyLoad