Is there a way to have a computed property observe the current time (for use in a timestamp)?
For example in my controller I might have a method that looked something like this:
formatLastUpdated:function() {
return moment(this.get("model.update_ts")).fromNow();
}.property("model.update_ts", "date.now?"),
The ember-time repository includes a good example of what you are trying to do.
They use a custom view via a handlebars helper. The view sets up a tick
function which is called every second via Ember.run.later
:
didInsertElement: function() {
this.tick();
},
tick: function() {
var nextTick = Ember.run.later(this, function() {
this.notifyPropertyChange('value');
this.tick();
}, 1000);
this.set('nextTick', nextTick);
},
willDestroyElement: function() {
var nextTick = this.get('nextTick');
Ember.run.cancel(nextTick);
}
The notifyPropertyChange
call tells the view that the property has changed and so triggers the re-render...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With