0

I've copied this code directly out of a book, and from what I can tell it should work, but it isn't. I'm not getting any errors, but the Recommendation value is just displaying the angular string (in curly braces), and the console.logs are never getting hit. Where am I going wrong? (Obviously there's a typo somewhere, but I don't know if it's my code or the book's).

<!DOCTYPE html>
<html>
    <head>
        <title>Calculator</title>
        <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
         <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/angularjs/1.0.6/angular.min.js"></script>
    </head>
    <body>
        <form data-ng-controller="CalcController">
            Starting: <input data-ng-change="computeNeeded()" data-ng-model="funding.startingEstimate">
            Recommendation: {{funding.needed}}
        </form>
        <script>
            function CalcController($scope) {
                $scope.funding = {startingEstimate:0};
                computeNeeded = function() {
                    console.log("running");
                    $scope.funding.needed = $scope.funding.startingEstimate * 10;
                    console.log("funding needed: " + $scope.funding.needed);
                };
                $scope.$watch('funding.startingEstimate', computeNeeded);
            }
        </script>
    </body>
</html>

1 Answer 1

1

Looks like this is missing an ng-app tag somewhere (I'd put it on the html). That directive tells Angular to bootstrap itself onto the page.

<html ng-app>

Edit: docs for ng-app: http://docs.angularjs.org/api/ng.directive:ngApp

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

2 Comments

DOH! Thanks. I should have known that much by now. Silly me for thinking that sample code should be correct.
Can't tell you how many times I've forgotten ng-app on my own code (hint: one per new html file).

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.