Reputation: 1560
I need some help guys. Just had to learn angular, I was setting my up just like this.
Here is my file structure.
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'}
);
});
MY proble is I get this error. Is it there a way that the way i want it could work?
when I move the
<script type="text/javascript" src="controllers/AboutController.js"></script>
in index, it will work. Please correct me if I'm in a wrong path
Error: [ng:areq] http://errors.angularjs.org/1.2.25/ng/areq?p0=AboutController&p1=not%20aNaNunction%2C%20got%20undefined at Error (native)
Upvotes: 0
Views: 3951
Reputation: 42669
AngularJS needs all controller, services, directives and filters to be registered at the config
stage before the app can run. Lazy loading is not supported out of the box. Therefore all you scripts have to be registered in index pages, so you are doing fine.
For lazy loading you need to look at some custom components like these https://github.com/ocombe/ocLazyLoad
https://github.com/nikospara/angular-require-lazy
Upvotes: 3