javascript - AngularJS - function within controller isn't being called as I would expect in simple example -
for following html , js controller, why 'clear' button not triggering function?
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.4.3/angular.min.js"></script> <script src="app.js"></script> </head> <body ng-app="app" ng-controller="resetcontroller reset"> <div> <label>name:</label> <input type="text" ng-model="yourname" placeholder="enter name here"> <button ng-click="clearname">clear</button> <hr> <h1>hello {{yourname}}!</h1> </div> </body> </html> and app.js file
angular.module('app', []) .controller('resetcontroller', function($scope) { $scope.yourname = 'start'; $scope.clearname = function(){ console.log('clearing name...'); $scope.yourname = ''; }; });
clearname() function need parenthesis.
<button ng-click="clearname()">clear</button>
Comments
Post a Comment