1

I am doing a simple hello world example straight out of book but somehow i cant get it correct. not sure what is going on here.

html Code, angular.js is the latest 1.3.x downloaded from angularjs site

<!DOCTYPE html>

    <html ng-app>
    <head>
    <script src="angular.js"></script>
    <script src="controller.js"></script>
    </head>
    <body>
    <div ng-controller='HelloController'>
      <p>{{greeting.text}}, World</p>
    </body>
    </html>

Controller.js

function HelloController($scope){
  $scope.greeting={text:'Hello'};
}

why can i get Hello world in the output when i load the html page. Instead i see this

{{greeting.text}}, World

what is going on?

1
  • missing div closing tag?? Commented Oct 11, 2014 at 14:27

2 Answers 2

1

Here is what will work for you:

function HelloController($scope) {
    $scope.greeting={text:'Hello'};
}
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23/angular.min.js"></script>
<div ng-app>
  <div ng-controller="HelloController">
    <p>{{greeting.text}}, World</p>
  </div>
</div>

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

1 Comment

This works, why is that?. why cant i use local angular javascript file?
1
   <html>
    <head>
    <script src="angular.js"></script>
    <script src="controller.js"></script>
    </head>
    <body ng-app>
    <div ng-controller='HelloController'>
      <p>{{greeting.text}}, World</p>
    </div>
    </body>
    </html>

1 Comment

This is why I use IDEs that auto-add ending tags. ;)

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.