Javascript 只有在Angularjs中进行更改时,表单验证弹出窗口消息才有效
我有一个表单,需要显示验证错误弹出窗口消息,如果点击提交。 这是我的表格Javascript 只有在Angularjs中进行更改时,表单验证弹出窗口消息才有效,javascript,angularjs,forms,ionic-framework,Javascript,Angularjs,Forms,Ionic Framework,我有一个表单,需要显示验证错误弹出窗口消息,如果点击提交。 这是我的表格 <form ng-submit="register(user)"> <div class="list"> <label class="item item-input"> <input type="text" placeholder="First Name" ng-model="user.first" > </label> <label
<form ng-submit="register(user)">
<div class="list">
<label class="item item-input">
<input type="text" placeholder="First Name" ng-model="user.first" >
</label>
<label class="item item-input">
<input type="text" placeholder="Last Name" ng-model="user.last">
</label>
</div>
<button class="button button-positive">
button-positive
</button>
</form>
开始进行更改时,验证工作正常。但是,如果单击“提交”而不输入任何内容,则不会显示任何错误消息。我如何才能做到这一点?我也想
显示服务器请求的加载屏幕,当服务器请求完成时,它将丢失。我正在使用ionicframework,我知道ionic.loading用于此,但如何在我的代码中正确使用它?请帮助。有关问题的验证部分,我只需要检查
user
和user.firstname
:
if(!user || !user.first){ $ionicPopup.alert({
title: 'First Name Required!',
template:'Firstname'
});
将其注入控制器后,您可以使用$ionicload
,如下所示:
else {
$ionicLoading.show({ template: 'Loading...' });
Friends.setall(user).then(function(msg){
console.log("From server"+msg.data);
$ionicLoading.hide();
});
}
为什么不让Angular直接在表单上进行验证,而不是在控制器和弹出窗口中进行逻辑验证?如果是必填字段,则在其上添加HTML5属性
required
。否则,您可以检查表单是否为“$dirty
”。我在移动应用程序上工作过,我认为弹出消息比文本更适合于错误消息,因为用户可以轻松通知错误。您能给出答案吗?()
else {
$ionicLoading.show({ template: 'Loading...' });
Friends.setall(user).then(function(msg){
console.log("From server"+msg.data);
$ionicLoading.hide();
});
}