2017-02-02 4 views
0

私はangularjsを初めて使用しています。私はテキストボックスの価値を得るのにいくつか問題があります。そして、それは空の文字列を返すだけです。私はモデルのそれぞれを ""と等しいと宣言していると思います。ここに私のコードです:でanglejsでテキストボックスの値が空に戻ります

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

間違った関数名代わりの$scope.account_update

here

他に何もあなたの角度のコードが間違っていないplnkr例を参照してください。

さらにif(isValid){}の代わりにif($scope.account.$valid){}を使用できます。値を渡す必要はありません。

関連する問題