0

I am new to angularjs. I have some issues in getting the value of the textbox. And it only returns an empty string, which I think because I declare each of the model equal to "". Here's my code:

HTML

<form name="account" ng-submit="update_account(account.$submitted && account.$valid)" novalidate> <input required placeholder="{{placeholderForName}}" name="name" ng-model="name" type="text"> <input required placeholder="{{placeholderForUname}}" name="uname" ng-model="uname" type="text"> <input required placeholder="{{placeholderForPassw}}" name="passw" ng-model="passw" type="password"> <button type="submit">Save!</button> </form> 

JS

$scope.name = ""; $scope.uname = ""; $scope.passw = ""; $scope.account_update = function(isValid){ if(isValid){ $http.post('query?action=tnoucca_etadpu',{ 'name': $scope.name, 'uname': $scope.uname, 'passw': $scope.passw }) .then(function(response){ alert(response.data); // alerts empty string }) .catch(function(response){ $scope.showToast("SYS_ERROR: " + response.data); }); } }; 

PHP

if ($action == "tnoucca_etadpu") { $data = json_decode(file_get_contents("php://input")); $name = $data->name; $uname = $data->uname; $pw = $data->passw; echo $name; } 

    1 Answer 1

    1

    Wrong function name in ng-submit="update_update(account.$submitted && account.$valid)" instead of $scope.account_update

    see example plnkr here

    Else nothing is wrong with your angular code.

    In Addition you can use :if($scope.account.$valid){} instead of if(isValid){} and don't need to pass any value.

      Start asking to get answers

      Find the answer to your question by asking.

      Ask question

      Explore related questions

      See similar questions with these tags.