2013-10-14 61 views
0

我已经阅读了几个关于类似问题的例子,但似乎无法使其工作。Angularjs,输入文字清晰

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

输入文本框已经添加的名字,并允许你如果按Enter键添加一个新的箱子都过滤。我想这样做以便当你按下enter并调用submit()函数时,文本输入字段被清除。

$scope.newAccomp = ""; 

感谢您的帮助。

回答

3

你提到需要被拉出“addToAccount”方法的代码行,并在“提交”方法运行。

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; 
     } 
    } 
} 

我这样做,你的例子工作正常。

+0

我有同样的问题,我不能清除输入字段。查看$ scope,我清除的值不存在。很奇怪。 – andyczerwonka

2

我相信你正在寻找ngSubmit

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