0

I need some help guys. Just had to learn angular, I was setting my up just like this.

Here is my file structure. enter image description here

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)

1
  • try to declare your controller as angular.module('TestingAngular').controller('AboutController',function($scope){}); Commented Sep 19, 2014 at 6:41

1 Answer 1

3

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.