Clearing input after form submission in angularjs -


i have confusion when clearing input after form submission. code below.

html :

<form novalidate method="post">    <input ng-model="person.firstname" type="text" id="firstname" /> <button ng-click="edit(person)" name="savebtn" >{{text}}</button> 

controller :

app.controller('personctrl', function ($scope, $routeparams, personservice) {      $scope.init = function () {        $scope.person = {};     };      $scope.edit = function (person) {         personservice.insertperson(person.firstname);         person.firstname = "";     };      $scope.init(); }); 

question: if use person.firstname = ""; or $scope.person.firstname = ""; both have same behaviour , clear input fine. how knows person.firstname in html not mentioning scope*?*. don't know if valid question whenever need interact html binding value need use $scope.

it's because $scope.person , person points same object in $scope.edit function ($scope.person === person true).


Comments

Popular posts from this blog

SPSS keyboard combination alters encoding -

Add new record to the table by click on the button in Microsoft Access -

CSS3 Transition to highlight new elements created in JQuery -