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

J. Davidson
  • 3,297
  • 13
  • 54
  • 102
  • 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. – shaunhusain Jun 05 '14 at 08: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 – J. Davidson Jun 05 '14 at 08: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. – shaunhusain Jun 05 '14 at 08: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; }); – J. Davidson Jun 05 '14 at 08: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 http://stackoverflow.com/questions/17667455/angular-http-vs-service-vs-ngresource – shaunhusain Jun 05 '14 at 08:51
  • @shaunhusain can you point me or show me how to use the promise in this situation as i am not that familiar with it. Thansk – J. Davidson Jun 05 '14 at 08:54
  • Sure something like this http://stackoverflow.com/questions/19490560/angularjs-resource-promise but in your case you are wanting to get the promise returned from doing the save then make a call to the get/query function again. – shaunhusain Jun 05 '14 at 08:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/55116/discussion-between-j-davidson-and-shaunhusain). – J. Davidson Jun 05 '14 at 09:30
  • Ah sorry just getting to bed will try to remember to check back tomorrow – shaunhusain Jun 05 '14 at 09:56

0 Answers0