Stack Overflow is a community of 4.7 million programmers, just like you, helping each other.

Join them; it only takes a minute:

Sign up
Join the Stack Overflow community to:
  1. Ask programming questions
  2. Answer and help your peers
  3. Get recognized for your expertise

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

share|improve this question
up vote 3 down vote accepted

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

share|improve this answer
    
it works..thanks.. so is it adding object featureToAdd to phone so each phone has featureTo add? – Arief Goldalworming Sep 28 '13 at 2:42
    
Yes, exactly. :) – Langdon Sep 30 '13 at 12:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.