【问题标题】:AngularJS : Model update detection and change event [closed]AngularJS:模型更新检测和更改事件
【发布时间】:2013-07-01 07:44:04
【问题描述】:

我想知道使用 Angular 处理输入更改事件的最佳方法是什么。事实上,我们可以监听模型更新,但是不仅在输入更新结束时,每个输入的字符都会触发相应的监听器。

感谢您的帮助。 蒂埃里

【问题讨论】:

标签: angularjs


【解决方案1】:

您可以使用该示例来获得启发。这是带有ENTER 的指令:

app.directive('ngEnter', function() {
        return function(scope, element, attrs) {
            element.bind("keydown keypress", function(event) {
                if(event.which === 13) {
                    scope.$apply(function(){
                        scope.$eval(attrs.onEnter);
                    });

                    event.preventDefault();
                }
            });
        };
    });

HTML:

<div ng-app="" ng-controller="MainCtrl">
    <input type="text" ng-enter="doSomething()">    
</div>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2012-01-16
    • 2014-02-13
    • 2013-12-02
    • 1970-01-01
    • 2013-04-15
    • 2013-04-11
    相关资源
    最近更新 更多