1

I am learning AngularJs. I am creating my first application on Plunker but it fails to initialize the controller. what am i missing exactly?

Here is the link of my plunker project

    <html ng-app>

<head>
  <script data-require="angular.js@*" data-semver="1.4.0-beta.1" src="https://code.angularjs.org/1.4.0-beta.1/angular.js"></script>
  <link rel="stylesheet" href="style.css" />
  <script src="script.js"></script>
</head>

<body ng-controller="testcontroller">
  <h1>Hello {{message}}</h1>
</body>

</html>

var testcontroller = function($scope) {
  $scope.message = "world";
};
4
  • 1
    <html ng-app>.. here you need to give app name.. Commented Jan 23, 2015 at 6:17
  • That is not necessary as long as i m not using modules Commented Jan 23, 2015 at 6:19
  • You need it man.. go to documentation of AngulaJS Commented Jan 23, 2015 at 6:22
  • I got it. using ng-App without module name was working flawlessly with previous releases like 1.3.0-beta.5 but Angular no longer supports this functionality Commented Jan 23, 2015 at 6:30

1 Answer 1

1

Here is Plunkr

Declare ng-app="myApp"

You are defining controller in wrong way

angular.module('myApp',[])
.controller('testcontroller', function($scope){
  $scope.message="world";
});
Sign up to request clarification or add additional context in comments.

2 Comments

is it mandatory to assign a module for the application? because i have seen many examples working with only ng-app
modular approach separates the code better way docs.angularjs.org/guide/module

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.