0

I basically copied this code from a video tutorial from the official site. I wish '4' were shown on the screen, but it keeps showing '{{ totalTodos }}'. Here index.js:

function TodoCtrl($scope) {
    $scope.totalTodos = 4;
}

And here index.html:

<html ng-app>
    <head>
        <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script>
        <script type="text/javascript" src="index.js"></script>
    </head>
    <body>
    <div ng-controller="TodoCtrl">
        {{ totalTodos }}
    </div>
    </body>
</html>
Corsys
  • 55
  • 7

1 Answers1

1

It's good practice to start correctly if you are newbie in angularJs. Start by creating module and give it any name. I used app as a module name and then your controller and so on ..

angular.module("app", []).controller("TodoCtrl", function ($scope) {
    $scope.totalTodos = 4;
});
<html ng-app="app">
        <head>
            <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.6.5/angular.min.js"></script>
            <script type="text/javascript" src="index.js"></script>
        </head>
        <body>
        <div ng-controller="TodoCtrl">
            {{ totalTodos }}
        </div>
        </body>
</html>
Niroda
  • 320
  • 1
  • 3
  • 13