0

I am following a tutorial but stuck on one issue. I don't know what I am missing here.

    //script.js
    var MainController = function($scope)
    {
      $scope.message = "Hello!!!!";
    };

<!-- index.html -->
<!DOCTYPE html>
<html ng-app>

  <head>
    <script data-require="[email protected]" data-semver="1.3.4" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js"></script>
    <link rel="stylesheet" href="style.css" />
    <script src="script.js"></script>
  </head>

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

</html>

Problem is - The message is not binding.

3
  • Turn your code into a single file chunk and re post your question. (with the code) Commented Nov 26, 2014 at 4:25
  • Try this: change <html ng-app> to <html ng-app="app"> and your javascript to angular.module("app", []) .controller("MainController", function() {});. Commented Nov 26, 2014 at 4:38
  • 1
    your code will work with Angular 1.0.7, I guess things changed a bit , have a look at viralpatel.net/blogs/angularjs-controller-tutorial Commented Nov 26, 2014 at 4:44

1 Answer 1

1

Create your module first, then add the controller to the module, specify both the app and controller in your HTML portion.

<!DOCTYPE html>
<html ng-app="app">

  <head>
    <script data-require="[email protected]" data-semver="1.3.4" src="//ajax.googleapis.com/ajax/libs/angularjs/1.3.4/angular.min.js"></script>
     <script>
     var app = angular.module('app',[]);
      var MainController1 = function($scope)
      {
        $scope.message = "Hello!!!!";
      };
      app.controller("MainController1", MainController1);

    </script>
  </head>

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

</html>
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.