title: How to handle localstorage in asynchronous way?
body: <p>In my typescript application, i am having two files say,</p>
  
  <p><code>File 1</code> and <code>File 2</code>,</p>
  
  <p>Whereas in <code>File 1</code>, i would like to store a value in localstorage like,</p>
  
  <pre><code>private load() {
  
  return this.entityService
        .load(this.$scope.projectRevisionUid)
        .then(resp =&gt; {
          localStorage.removeItem('employeerates');
          this.$scope.employeeRates = resp.employeeRates;
          return this.refreshCostRate(...resp.employeeRates)
            .then(() =&gt;
              localStorage.setItem(
                'employeerates',
                JSON.stringify(this.$scope.employeeRates)
              )
            )
        .then(() =&gt; this.refreshBillRate(...resp.employeeRates))
        .then(() =&gt; resp.employeeRates.forEach(erm =&gt; this.calculate(erm)))
        .then(() =&gt; DatepickerUtil.reinitializeDatepickers(this.$scope));
        })
  
  }
  </code></pre>
  
  <p>In <code>File 2</code>, i am having the following,</p>
  
  <pre><code>          const employeerates = JSON.parse(
              localStorage.getItem('employeerates')
            );
  
            if (employeerates &amp;&amp; employeerates.length != null) {
              employeerates.forEach((element: any) =&gt; {
                if (
                  this.employee.getUid() === element.user.personUid &amp;&amp;
                  element.internalRate
                ) {
                  this.cost_rate_uom = element.internalRate * this.uom_factor;
                  this.cost_rate_per_hour =
                    this.cost_rate_uom / this.uom_factor;
                  this.cost_rate.setValue(this.ap4_cost_rate_per_hour);
                }
              });
            }
  </code></pre>
  
  <p>Here setting localstorage in File 1 is asynchronous, i am unable to fetch the data at right time in <code>File 2</code>..</p>
  
  <p>Kindly help me to achieve the result of getting localstorage in file 2 without using setTimeOut (because it doesnot solve my issue as i have already checked).</p>
  
  <p>Please help me to pass localstorage value from one file to another which is async..</p>
  
  <p><strong>Update:</strong></p>
  
  <p>I couldn't get any other method of passing the data <code>this.$scope.employeeRates</code> from file 1 to file 2, for which i have used this localstorage method.. So after the async function <code>this.refreshCostRate(...resp.employeeRates)</code> i need to call the localstorage but before that itself my file 2 runs, but above the line <code>this.refreshCostRate(...resp.employeeRates)</code>, if i set the localstorage then i am getting localstorage in file 2, but the case is after refresh function only i will get the exact value..</p>
  
  <p>If you suggest any other way of passing data from one ts file to another ts file, then it would also be helpful.. Thing is after <code>this.refreshCostRate(...resp.employeeRates)</code> i will get the exact value for <code>this.$scope.employeeRates</code> which i need to send to <code>file 2</code>..</p>