0

I follow angular.js tutorial

I add list feature in object array and make form to add it.. I search and finally get how to add new feature to object but I don't know how to reset the form

this is the code.. http://plnkr.co/edit/O2xmL5

thanks

1 Answer 1

3

The problem is that you've created this variable but it's not necessarily tied to your scope... in fact, I'm not exactly sure where it's bound... perhaps form creates some sub-scope automatically?

Either way, I would recommend binding the input to a variable that your controller will have access to. A property on phone seems to make the most sense. After that, inside of $scope.addFeature, you can clear it out (or do whatever you want with it):

HTML:

<form ng-submit="addFeature(phone, phone.featureToAdd)">
    ...
    <input ... ng-model="phone.featureToAdd" ...>

JavaScript:

$scope.addFeature = function(phone,addfeature) {
    phone.features.push(addfeature);
    phone.featureToAdd = '';
};

I've implemented it here: http://plnkr.co/edit/wWwj4F

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

1 Comment

it works..thanks.. so is it adding object featureToAdd to phone so each phone has featureTo add?

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.