加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

AngularJs ng-change手动触发事件

发布时间:2020-12-17 17:56:29 所属栏目:安全 来源:网络整理
导读:input type="checkbox" value="" ng-model="filterPrivateDocCheckBox" ng-click="dl.filterPrivateDocument(filterPrivateDocCheckBox,$event)" input st-search="target" class="input-sm form-control" ng-model="dl.documentTarget" ng-change="dl.chang
<input type="checkbox" value="" ng-model="filterPrivateDocCheckBox" ng-click="dl.filterPrivateDocument(filterPrivateDocCheckBox,$event)">
 <input st-search="target" class="input-sm form-control"  ng-model="dl.documentTarget" ng-change="dl.change()" />

function filterPrivateDocument(val) 
{
    if(val)
    this.documentTarget = 'Private';
}

当我点击checkBox时,我将值设置为文本框,但是我看到ng-change事件没有被触发.为什么?

而且当我在文本框中输入一些值时,我发现ng-change事件被触发了.

解决这个问题的任何方法?

解决方法

根据 the docs:

The ngChange expression is only evaluated when a change in the input value causes a new value to be committed to the model.

It will not be evaluated:

  • if the value returned from the $parsers transformation pipeline has
    not changed
  • if the input has continued to be invalid since the model
    will stay null
  • if the model is changed programmatically and not by a
    change to the input value

因此,当它被JavaScript(/ angular)更改时不会被触发.

您可以做的是,自己触发更改功能:

function filterPrivateDocument(val) {
    if(val) {
        this.documentTarget = 'Private';
        this.change();
    }
}

见this jsfiddle

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读