2017-06-16 14 views
0

私は$ httpリクエストを持っています。私はボタンを押してリクエストを発しました。しかし、フォームの入力が空であれば要求をブロックします。 Required.butてみました、それはそれはそれはしたい要求を要求anyway.iを送信しますfunction.so提出するユーザーの場合にのみ送信することがありますボタンで入力がイオンで空の場合にリクエストを送信しない方法

$scope.submit=function() 
 
{ 
 

 
var loginServiceUrl = 'https://www.yabiladi.com/newsapi/login.json'; 
 
var loginServiceData = { 
 
    user: $scope.username, 
 
    password: $scope.password 
 
} 
 

 
$http.post(loginServiceUrl, loginServiceData). 
 
    then(function (res){ 
 
     $scope.drapeau=0; 
 
     console.log(res); 
 
     $scope.user=res.config.data.user; 
 
     
 
    }).catch(function(response){ 
 
      //rien 
 
}) 
 
       
 
}
<div ng-if="flag==2" ng-controller="loginCtrl"> 
 
<div ng-show="drapeau"> 
 
     <label for="field1"><span>Username:</span> <div class="loginform"><input type="text" class="input-field" name="field1" value="" ng-model="username" /></div></label> 
 
      <label for="field2"><span>Password:</span><div class="loginform"><input type="password" class="input-field" name="field2" value="" ng-model="password" /></div></label> 
 
     <div class="boutonlogin"> 
 
      <button class="button button-energized button-small" ng-click="submit()" style="width:80px">Login</button> 
 
     </div> 
 
      <label> 
 
      <b><center>if you don't have an account,you can signup</center></b> 
 
      </label> 
 
      <div class="boutonlogin"> 
 
      <button class="button button-energized button-small" ng-href="#/signup/{{flag}}" style="width:80px" ng-click="modal.hide()">Signup</button> 
 

 
      </div> 
 
    
 
    </div> 
 
      <div ng-hide="drapeau"> 
 
user connected : {{user}} 
 
</div> 
 
    </div>

を動作しませんでした入力が空であればログインとパスワードを入力するかボタンを無効にする

は助け

+0

を呼び出してくれてありがとう。パスワードは未定義){// $ http } else {アラート(「ユーザー名とパスワードを入力してください」) –

+0

@KalaiselvanAはかなりシンプルです。私はそれについて考えなかったのですが。 –

答えて

0

// nullをチェックして、(loginServiceData.user!= nullの&& loginServiceData.user!=未定義&& loginServiceData.password!= nullの&& loginServiceData場合$ HTTP

if(loginServiceData.user!=null && loginServiceData.password!=null){ 
// here you can use your $http call 
//$http.post() 

}else{ 
    alert("Please Enter Username && Password"); 
} 
関連する問題