Arturo Natho
Arturo Natho

Reputation: 1

Auto refresh template using emberjs

I am new in emberjs and having trouble auto refreshing a template. The main idea consists of a SPA where the user can check the minutes left for the product he has already purchased to arrive home. So that if he stays on the tracking template it should reload every 5 or 10 seconds updating the time info:

<script type="text/x-handlebars" onload="JavaScript:timedRefresh(5000);" data-template-name="pedido" >
  <div class="container text-center">
    <h2 class="text-error">{{name}}</h2>
    <small>Minutes left: {{ rest }} </small>
  </div>
</script>

Clearly this code is not working, can anyone help me out? Thanks!

Upvotes: 0

Views: 1008

Answers (2)

Stanislav Ryahov
Stanislav Ryahov

Reputation: 131

Remove onload from template and insert your code in coontroller. For example:

App.PedidoController = Ember.ObjectController.extend({
  init: function() {
    var self = this;
    setInterval(function() {
      self.refreshMyData()
    }, 5000);
  },
  refreshMyData: function() {
    foo();
    bar();
  }
});

Upvotes: 3

simon
simon

Reputation: 943

You need to stay within the Ember system for things to work nicely. You should be able to work it out by looking at this quick example. Let me know if you need more :)

http://emberjs.jsbin.com/eruwilU/1/

Good luck!

Upvotes: 2

Related Questions