javascript - AngularJS error loading Controller -


i have dumb problem don't know how fix it. have index.html file angularjs loaded. i'm using plunker test code:

<!doctype html> <html ng-app="">    <head>     <script data-require="angular.js@1.4.8" data-semver="1.4.8" src="https://code.angularjs.org/1.4.8/angular.js"></script>     <link rel="stylesheet" href="style.css" />     <script src="script.js"></script>   </head>    <body ng-controller="bodycontroller">     <h1>{{ message }}</h1>   </body>  </html> 

and script.js file information:

var bodycontroller = function($scope) {   $scope.message = "hi angular!" } 

in inspector says:

error: [ng:areq] argument 'bodycontroller' not function, got undefined 

the script loaded. have defined controller in js file , attach ng-controller directive, don't know can fail.

this basic of angularjs.

you first need create module:

var fooapp = angular.module("foo", []) 

and then, register controller there:

var bodycontroller = function($scope) {   $scope.message = "hi angular!" } fooapp.controller("bodycontroller", bodycontroller); 

and, in html tag, change ng-app this:

<html ng-app="foo"></html> 

Comments