javascript - The controller function is not being called -
i'm learning angularjs , complete courses in internet know module, controller, service, know basics directives, , found in internet basic angularjs video tutorial, i'm doing in video can't understand why it's not work. here code
var app = angular.module('todoapp', []); app.controller('todoctrl', ['$scope', function($scope) { $scope.todos = [ { text: "learn angularjs" }, { text: "build app" } ]; $scope.addtodo = function() { $scope.todos.push({text: $scope.todotext}); }; }]); <html ng-app="todoapp"> <head> <title>todo</title> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.3.15/angular.min.js"></script> <script src="/underscore-master/underscore-min.js"></script> <script src="todo.js"></script> <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.4/css/bootstrap.min.css"> </head> <body> <div ng-controller="todoctrl"> <h2>total todos: {{todos.length}}</h2> <ul class="unstyled"> <li ng-repeat="todo in todos"> <span>{{todo.text}}</span> </li> </ul> </div> <form class="form-horizontal"> <input type="text" ng-model="todotext"> <button class="btn" ng-click="addtodo()"><i class="icon-plus">add</i></button> </form> </body> </html> it should insert new text in array, when i'm clikcking on button nothing happens, , no error in console, realy can't understand why?
the ng-click event out of controller's scope. quick answer move ng-controller="todoctrl" enclosing/outer element, body in case.
Comments
Post a Comment