natecraft1
natecraft1

Reputation: 2836

Angularjs, clear input text on enter

I've read several examples on here about similar issues but nonetheless can't seem to get it to work.

Here's the fiddle: http://jsfiddle.net/natecraft/jtMAq/7/

The input text box is both filtering already added boxes by name and allowing you to add a new one if you press enter. I want to make it so that when you press enter and call the submit() function, the text input field is cleared.

$scope.newAccomp = "";

Thanks for the help.

Upvotes: 0

Views: 3144

Answers (2)

frosty
frosty

Reputation: 21762

The line of code you have mentioned needs to be pulled out of the "addToAccount" method, and run in the "submit" method.

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

I did this, and your example worked fine.

Upvotes: 3

vittore
vittore

Reputation: 17579

I belive you are looking for ngSubmit

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

Upvotes: 2

Related Questions