0

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.

2 Answers 2

3

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.

Sign up to request clarification or add additional context in comments.

1 Comment

I have the same problem, and I can't get the input field to clear. Looking in the $scope, the value I'm clearing is not there. Very strange.
2

I belive you are looking for ngSubmit

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.