Angularjs,输入时清晰的输入文本

时间:2013-10-14 04:56:45

标签: forms angularjs input

我已经在这里阅读了几个关于类似问题的例子,但似乎无法让它发挥作用。

这里是小提琴:http://jsfiddle.net/natecraft/jtMAq/7/

输入文本框既按名称过滤已添加的框,又允许您按Enter键添加新框。我想这样做,当你按Enter键并调用submit()函数时,文本输入字段将被清除。

$scope.newAccomp = "";

感谢您的帮助。

2 个答案:

答案 0 :(得分:3)

您提到的代码行需要退出“addToAccount”方法,并在“submit”方法中运行。

function accomplishmentController($scope) { 

    $scope.accomplishments = [];
    $scope.submit = function() {
        $scope.accomplishments.unshift({ name: $scope.newAccomp, count: 0 });
        **$scope.newAccomp = '';**
        $scope.addToCount = function() {
            var currentcount = this.accomp.count;
            this.accomp.count = currentcount + 1;
        }
    }
}

我这样做了,你的例子运行正常。

答案 1 :(得分:2)

我相信您正在寻找ngSubmit

 <input type="text" ng-model="newAccomp" ng-submit="addToCount()" />
相关问题