javascript - Angular two way binding does not appear to work while the documentation says that it should -
i trying use value of $scope.commenttext when call addcomment() scoped variable empty eventhough bound. workaround pass commentext parameter value works still should work. question how clear out commenttext bound text input ... not work expected either. looked around... , missing cause doing docs tell me how to. so... anyone?
$scope.user = "wm"; $scope.commenttext=''; $scope.addcomment = function(plan, commenttext) { console.log(commenttext) plan.comments.push({text:commenttext, user:$scope.user); commenttext=null; $scope.commenttext=null; };
and view:
<form ng-submit="addcomment(plan, commenttext)"> <div class="input-group"> <input class="form-control" type="text" ng-model="commenttext" size="30" placeholder="add new comment here"> <span class="input-group-btn"> <input class="btn btn-primary" type="submit" value="add"> </span> </div> </form>
plunker: http://plnkr.co/edit/lg0ckjctsj9hu83ltydh?p=preview
use this.commenttext=null;
instead of $scope.commenttext=null
in addcomment
method.
updated plunkr
edit: started typing explanation when noticed there excelent 1 right here: 'this' vs $scope in angularjs controllers
Comments
Post a Comment