简体   繁体   English

触发日期更改时不会触发 ng-change 事件

[英]ng-change event is not triggering when date change is fired

Hi I am new to angular js.嗨,我是 angular js 的新手。 Currently my scenario is when i change the date it should trigger the method where it opens the modal .but in my case i am using ng-change event to call the method where by using this the call is not fired on date change.目前我的情况是,当我更改日期时,它应该触发它打开模态的方法。但在我的情况下,我使用 ng-change 事件来调用方法,通过使用此调用不会在日期更改时触发。 but if i use the ng-click method on click of date field will open the modal which should not happen on change of date only it should open modal.但是,如果我在单击日期字段时使用 ng-click 方法将打开不应在更改日期时发生的模态,只有它应该打开模态。 so how i can achieve this?那么我如何才能做到这一点?

HTML code: HTML代码:

<div class="input-wrap-container row">
  <field ng-model="requisition.validityStartDate" class="col-xs-4"
         editable="true"
         ng-change ="validityStartDate(requisition.validityStartDate)">
  </field>`
</div>

This is my JS code`:这是我的 JS 代码`:

var validityStartDate = function (validityStartDate) {
    newValueStartDate = validityStartDate;
    debugger
    if (newValueStartDate != null && newValueStartDate != oldValueStartDate) {

        var apprModalId = "changeValidityDates";

        $element.find('#'+ apprModalId).modal("show");
        oldValueStartDate = newValueStartDate;
        newValueStartDate = null;

        $element.find('#'+ apprModalId).on('shown.bs.modal', function () {
            console.log("submit-req error modal shown");

        //scope.buttonActionReqError = response;
        });   
    }
};

Evaluate the given expression when the user changes the input.当用户更改输入时评估给定的表达式。 angularjs doc angularjs 文档

Since you are not using an input field, ngChange will not fire.由于您没有使用输入字段,因此ngChange不会触发。

Change <field> to <input><field>更改为<input>

UPDATE TO MATCH COMMENT更新以匹配评论

onKeyup上键

I guess you could do ng-keyup="expression" if you wanted, or keyDown or anything else that is triggered by a keypress.我想你可以根据需要执行ng-keyup="expression" ,或者 keyDown 或其他任何由按键触发的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM