$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 :(得分:0)
//检查null并调用$ http
if(loginServiceData.user!=null && loginServiceData.password!=null){
// here you can use your $http call
//$http.post()
}else{
alert("Please Enter Username && Password");
}