1

Below code is not giving output as expected i:e Hello,World output: {{ greetings.text }}, world

Can anyone help me why its not displaying 'hello, world' instead where I am wrong

<!doctype html>
    <html ng-app>
    <head>
    <meta charset="utf-8">
    <title>Angular JS App 1</title>
    <script type="text/javascript" src="angular-v1.4.js"></script>
    <script type="text/javascript" src="controllers.js"></script>
    </head>

    <body>
        <div ng-controller='HelloController'> //controller
            <p>{{ greetings.text }}, World</p>
        </div>
    </body>
    </html>

script for controller

function HelloController($scope){
    $scope.greetings = {text : 'hello'};
}
4
  • Post you script please. Commented Dec 17, 2015 at 10:38
  • Post your controller definition Commented Dec 17, 2015 at 10:39
  • I think your ng-app is missing Commented Dec 17, 2015 at 10:40
  • added the script for controller Commented Dec 17, 2015 at 10:42

3 Answers 3

4

Global controller isn't allowed from 1.3.x

Try like this

var app = angular.module("app", []);
app.controller("HelloController", function($scope) {
    $scope.greetings = {
        text: 'hellow world'
    }
});

HTML

add module name

<html ng-app="app">
Sign up to request clarification or add additional context in comments.

1 Comment

thanks I was learning from old book.any suggestion on where to learn angularjs
1

add module name in ng-app.. like

<div ng-app='app'>
</div>

like this

<script>
  angular.module('app', [])
    .controller('testCtrl', ['$scope', function($scope){
      $scope.test ="hello world";
    }])
</script>

plunker code here

Comments

0

You need to provide the value for ng-app directive.

Like

<html ng-app="myapp">

and you should have the angular module myapp defined in script.

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.