0

I want to know how to retain the value in the textbox after we change the page and then come back again to the same page. Here I have a page called Transaction that accepts a value via textbox and when I click on its search button it shows the details by searching through the database. And then in the input data, I have a button called as Payload that when clicked shows Payload Data, now when I cancel that Payload page, Transaction page reloads (comes back) but without any data(entry) in the search box. I want the same data on basis of which search occurred to appear in the textbox again.

enter image description here

   <td style="width:50%">
     <input class="form-control" id="input1-group1 " style="margin-top:20px" 
   type="text" name="search" placeholder="Enter Search Text"
    [(ngModel)]="filterdata" >
    </td>
    <td style="width:50%">
       <button type="submit" class="input-group-addon" 
       style="margin-left:0px;width:65px;margin-top:20px" id="faIcon" 
       (click)="searchByText(filterdata)">
       &nbsp;&nbsp;&nbsp;
      <i class="fa fa-search "></i>
    </button>
    </td>
rk_1
  • 106
  • 2
  • 13
  • u mean wen ur textbox data is empty then also its refresh? –  May 15 '18 at 10:22
  • means ... when i return to the same page... the textbox is empty ..not the data that i previously searched with in the textbox –  May 15 '18 at 10:31
  • i think you need to use parent-child relationship in component to retain `[(ngModel)]` or use shared service(not recommanded). – Sanoj_V May 15 '18 at 10:35
  • i used localStorage (i.e. session) to store the value. But i donno what to use to display the value ..it is (change) or (ngValue) or (ngModelChange) or name .... wht is it –  May 15 '18 at 10:42
  • Check if this can solve your problem [click here](https://stackoverflow.com/questions/35327929/angular-2-ngmodel-in-child-component-updates-parent-component-property) – Deepshikha Chaudhary May 15 '18 at 10:50
  • Hi Deepshikha .... i want to ask if i need to implement this in template tag only - template: `

    Child: {{sharedVar}}

    ........because in my component i have templateUrl: './transaction.component.html' <-- like this. Can i implement it in my html directly
    –  May 16 '18 at 03:34

1 Answers1

0

Use a component to store the data and make the others components childs of it, when your application come back just take the values with @Input something and show the data on text box with [(ngModel)]="something"

Rancio
  • 155
  • 1
  • 3
  • 15