-1

i am new in angularjs and nodejs, What i am doing is create a html file name of index.html and make a controller.js file in which printing a console.log message but getting error on browser in console box my code is as follow

<html ng-app>

 <head>
 <title> App </title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">

 <body>
     <div class="container" ng-controller="AppCtrl">
    <h1> Contact List App </h1>
      <table class="table table-bordered">
        <thead>
            <tr>
                <td> name </td>
                <td> Email </td>
                <td> mobile </td>
            </tr>
        </thead>
        <tbody>

        </tbody>
    </table>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.3/angular.min.js"></script>
<script src="controllers/controller.js"></script>

and controller.js code is as follow

 function AppCtrl() {
  console.log("Hello Bro")
                 }
Amit Chauhan
  • 1,810
  • 3
  • 17
  • 25
  • 1
    You haven't declared a top-level module to set `ng-app=(module)`. You need to create that module then you can define your controller based off that module. (i.e. `angular.module('myTopLevelModule').controller('AppCtrl', AppCtrl);` – Ben Mar 27 '17 at 18:47
  • I see: No reference to angular.js, to your main module. Also there is no registration of your controller in your code file, just a function. I recommend you find a tutorial and do that first. – Igor Mar 27 '17 at 18:47
  • Possible duplicate of [Controller not a function, got undefined, while defining controllers globally](http://stackoverflow.com/questions/25111831/controller-not-a-function-got-undefined-while-defining-controllers-globally) – Satpal Mar 27 '17 at 18:48
  • i saw a video in which a coder done exactly what i write but his code works successfully. – Amit Chauhan Mar 27 '17 at 18:50
  • Error: [$controller:ctrlreg] http://errors.angularjs.org/1.6.3/$controller/ctrlreg?p0=AppCtrl at angular.js:38 at angular.js:10835 at ba (angular.js:9924) at n (angular.js:9694) at g (angular.js:9048) at g (angular.js:9051) at g (angular.js:9051) at angular.js:8913 at angular.js:1914 at m.$eval (angular.js:18172) – Amit Chauhan Mar 27 '17 at 18:50
  • this error is generating in console – Amit Chauhan Mar 27 '17 at 18:50

1 Answers1

0

First of all you cannot call this a Angular App.

You dont have the module. Declare a module as follows,

 var app = angular.module('todoApp', []);

Register a controller,

app.controller("dobController", ["$scope",
      function($scope) {
}

You have not refered the angular reference.

DEMO

var app = angular.module('todoApp', []);
app.controller("dobController", ["$scope",
  function($scope) {
    console.log("Hello Bro");
  }
]);
<!DOCTYPE html>
<html ng-app="todoApp">
<head>
  <title>To Do List</title>
  <link href="skeleton.css" rel="stylesheet" />
  <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.7/angular.min.js"></script>
</head>
<body ng-controller="dobController">
  <div class="col-md-20">
   </div>
</body>

</html>
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396