Angularjs 避免在用户完成输入之前触发ng更改

Angularjs 避免在用户完成输入之前触发ng更改,angularjs,Angularjs,我的问题是,用户更改签入日期,然后继续设置签出日期,但在他有机会完成签出日期的设置之前,ng change from签入日期触发虚拟机。setDates并中断他完成日期选择 <head> <meta charset="utf-8" /> <title>AngularJS Plunker</title> <script>document.write('<base href="' + document.lo

我的问题是,用户更改
签入日期,然后继续设置
签出日期,但在他有机会完成
签出日期的设置之前,ng change from
签入日期触发
虚拟机。setDates
并中断他完成日期选择

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>
这是我的密码:

<input type="date" ng-model="vm.checkin" id="checkinDate" ng-change="vm.setDates(vm.checkin, vm.checkout)" ng-model-options="{debounce:3000}">
<input type="date" ng-model="vm.checkout" id="checkoutDate" ng-change="vm.setDates(vm.checkin, vm.checkout)" ng-model-options="{debounce:3000}">
  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>


有没有一种方法可以让ng更改不会在签入字段中触发,只要用户在签出字段中执行操作?(或者如果可能的话,它有焦点?)

如果希望仅在用户选择签出日期时触发查询,则可以仅在签出日期字段中使用
ng change=“vm.setDates(vm.checkin,vm.checkout)

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>
如果出现以下情况,则可能出现问题: 1.当用户只选择签出日期而不选择签入日期时,在这种情况下,您可以禁用签出字段,直到签入字段为空。
2.当用户选择两个日期,但现在再次仅更改入住日期时,因此在这种情况下,如果用户更改入住日期,您可以清除“签出日期”值,您可以使用ng focus和ng blur来实现这一点。我创建了一个Plunk来模拟这一点。ng change函数仅显示修改后的数据,因为我不确定ng ch是什么ange函数在应用程序中不起作用。您可以在“modifyInput()”函数中修改if条件,使其符合您的需要。使用ng focus和ng blur上的标志应该可以实现。
  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>
我没有太多地使用if条件,因为我不确定您的具体需求是什么。就像上面提到的不同场景@Varun

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>
HTML:

  <head>
    <meta charset="utf-8" />
    <title>AngularJS Plunker</title>
    <script>document.write('<base href="' + document.location + '" />');</script>
    <link rel="stylesheet" href="style.css" />
    <script data-require="angular.js@1.5.x" src="https://cdnjs.cloudflare.com/ajax/libs/angular.js/1.5.11/angular.min.js" data-semver="1.5.11"></script>
    <script src="app.js"></script>
  </head>

  <body ng-controller="MainCtrl">
    <p>Hello {{name}}!</p>
    <input type="text" ng-model="input1" ng-change="modifyInput()" ng-focus="input1flag=true" ng-blur="input1flag=false">
    <input type="text" ng-model="input2" ng-change="modifyInput()" ng-focus="input2flag=true" ng-blur="input2flag=false">
    <p>Input 1 : {{input1_mod}}</p>
        <p>Input 2 : {{input2_mod}}</p>
<button ng-click="display()">submit</button>
<div ng-show="btnClick">
    <h4>{{input1_mod}}</h4>
        <h4>{{input2_mod}}</h4>
    </div>
  </body>

</html>

您可以在“vm.setDates”中添加一个条件,以查看是否同时设置了“vm.checkin”和“vm.checkout”,然后才运行该函数{如果用户只是在那里更改其中一个日期,则无效。如果用户只是在那里更改其中一个日期,那么如果他只是更改签入日期,则无效。我需要的是查看用户是否对其中一个日期字段具有焦点。如果要在焦点中执行操作,请选择ng焦点,当输入I时,它会起作用s in focus statevjay这是一个出色的解决方案!!
ng focus=“input1flag=true”ng blur=“input1flag=false”
逻辑性和优雅性-正是我想要的-非常感谢!!我刚刚完成了everywhere的实现,它就像一个charmGlad一样工作,我可以帮助:)