Ricardo Patrick
Ricardo Patrick

Reputation: 21

Why doesn't my variable render in my view after populating it in my controller?

What am I doing wrong? angular.min.js is in the folder js. I am using the book from O'Reilly. There is an example like this. But on my PC it doesn't work.

//controller.js

function HelloController($scope) {
    $scope.greeting = { text: 'Hello' };
}
<!DOCTYPE html>
<html>
    <head>
        <script type="text/javascript" src="js/angular.min.js"></script>
        <script type="text/javascript" src="js/controller.js"></script>
    </head>
<body ng-app="">
    <div ng-controller='HelloController'>
        <p>{{greeting.text}}, World</p>
    </div>
 </body>

</html>

Upvotes: 0

Views: 107

Answers (1)

GrabNewTech
GrabNewTech

Reputation: 641

  1. I think you are referring to old book. Please update your controller as below

    //controller.js
    var app = angular.module('myApp', []);
    app.controller('HelloController', function($scope) {
        $scope.greeting = { text: 'Hello' };
    });

and in HTML ng-app="myApp"

Please try and let us know whether it is working or not

Upvotes: 1

Related Questions