只有在Angularjs中进行更改时,表单验证弹出窗口消息才有效 [英] Form validation popup window message works only if change is made in Angularjs

查看:106
本文介绍了只有在Angularjs中进行更改时,表单验证弹出窗口消息才有效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果点击提交,我需要显示验证错误弹出窗口消息的表单。
这里是我的表单。

I have a form which need to show validation error popup window message if clicked submit. Here is my form.

 <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>

以下是验证控制器文件

 angular.module('starter.controllers',[])

.controller('DashCtrl', function($scope,$ionicPopup,Friends) {


    $scope.register=function(user){
      if(!user.first){ $ionicPopup.alert({
                       title: 'First Name Required!',
                       template:'Firstname'
                       });
      }else{
            if(!user.last){
                           $ionicPopup.alert({
                           title: 'Last Name Required!',
                           template:'Lastname'
                           });
              }else {


                        Friends.setall(user).then(function(msg){
                             console.log("From server"+msg.data);

                          });
              }

        }
    }

})

验证在开始进行更改时正常工作。但它不显示任何错误消息如果点击提交而不输入任何内容。我可以如何实现这一点?我也希望
显示服务器请求的加载屏幕,并且当服务器请求完成时就会消失。我正在使用ionicframework,并且我知道 ionic.loading 是用于这个,但我怎么能正确使用这在我的代码?。请帮助。

Validation works normally when start making changes. But it doesn't show any error messages If clicked submit without entering anything.How can i achieve this? also i want to show loading screen for the server request and it is dissmissed when the server request is complete.I am using ionicframework,and i know ionic.loading is used for this but How can i properly used this in my code?.Please help.

推荐答案

对于您的验证部分问题,我只需检查 user 以及 user.firstname

For the validation part of your question, I would just check for user along with user.firstname:

if(!user || !user.first){ $ionicPopup.alert({
  title: 'First Name Required!',
  template:'Firstname'
});

,您可以使用 $ ionicLoading 注入到控制器中,如下所示:

and you can use $ionicLoading, after injecting it into the controller, like this:

else {
  $ionicLoading.show({ template: 'Loading...' });
  Friends.setall(user).then(function(msg){
    console.log("From server"+msg.data);
    $ionicLoading.hide();
  });
}

这篇关于只有在Angularjs中进行更改时,表单验证弹出窗口消息才有效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆