【问题标题】:Angularjs input is not changing when updating via JS and not manual通过 JS 而不是手动更新时,Angularjs 输入不会改变
【发布时间】:2015-05-09 13:22:57
【问题描述】:

我有一个简单的表单,当我输入输入时,我会看到更改。
但是当我通过 JS 动态执行时,绑定并没有改变:

    <div ng-app>
        type here and see how the binding changes: 
<input type="text" id="test" ng-model="name" />
        <br /><br />
        Changes and binding <span style='color:red'>{{name}}</span><Br /><Br />

       <button onclick="document.getElementById('test').value = 'blaaaa'">Click and see how the binding is not changing</button>
    </div>

http://jsfiddle.net/hge2hnc4/

【问题讨论】:

    标签: javascript jquery angularjs binding


    【解决方案1】:

    这是因为,当您单击按钮时,您尝试更改文本框值而不是文本框模型 (name) 值,如果您更改模型 name 值,您将能够看到更新

    Here is a forked Demo

    【讨论】:

      猜你喜欢
      • 2015-12-14
      • 2023-03-08
      • 2017-03-25
      • 2014-06-18
      • 2018-06-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多