Arief Goldalworming
Arief Goldalworming

Reputation: 311

how to reset nested object form angularjs?

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

Upvotes: 0

Views: 350

Answers (1)

Langdon
Langdon

Reputation: 20073

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

Upvotes: 3

Related Questions