0

In my html I have code which dynamically adds rows when a button is clicked and on each row there is a button called "Add"

  <form name="{{form.name}}"
          ng-repeat="form in forms">
      <div ng-repeat="cont in form.contacts">
               <a href="/edit">Add</a>
              <input type="text" class="xdTextBox" ng-model="cont.ac"/>
              <input type="text" class="xdTextBox" ng-model="cont.a_number"/>
      </div>
      <button ng-click="submit(form)">Submit</button>
      <button ng-click="addFields(form)">Add</button>
      <hr>
    </form>

Than on my second page /edit i have following code that lists rows of values fetched.

<table>
<tbody ng-repeat="item in alllis">       
  <tr>
      <td>
         <a href="/main/{{item.id}">Select</a>
     </td>
     <td>
       <input type="text" ng-model="item.ac" />
     </td>
     <td>
    <input ng-model="item.a_number />
     </td>
   </tr>
  </tbody>
</table> 

What I am trying to figure out is when I am on /edit and I select any row how do i populate back that row data on main page. Please let me know from /edit page how do i go back to main page populating that row where Add button was clicked. Thanks Here is the plunker for the first (Main) page. http://plnkr.co/edit/VVUx2roDTrM9ob2uyZMv?p=preview

9
  • Are you storing the data somewhere, are you using a service at all... the plunkr doesn't really show enough about what your doing to answer this. Commented Jun 5, 2014 at 8:24
  • Data on the edit form is being retrieved from database that part is working fine. I just need to figure out when clicking one of the rows transfer the values for that row back to main page in the row where it was called from Commented Jun 5, 2014 at 8:26
  • Are you using an service you defined in angular for communicating with the service layer? Typically the service handles communicating with the service API and maintaining a local data model. Then the service can be injected into any number of controllers and can be used to create/read/update/delete elements from a data source, you can create an object or array in the service to hold the data and have a reference on the scope in the controller so you can display the data in the view. Commented Jun 5, 2014 at 8:36
  • @shaunhusain In my factory I am retrieving the data from db using following getAll: $resource('/api/allItems/Getitems', {}, {query: {method: 'GET', isArray:true}}) Than in my controller I have following $scope.alllis = itemRepository.getAll.query({}, function(data) { $scope.alllis = data; }); Commented Jun 5, 2014 at 8:47
  • Okay so since you have a $resource, you can use the promise from the resource call that you make to save and just have it call to get everything again also here's an answer I posted that might help stackoverflow.com/questions/17667455/… Commented Jun 5, 2014 at 8:51

0

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.