Skip to content

Instantly share code, notes, and snippets.

@siva-sundar
Last active December 10, 2015 07:50
Show Gist options
  • Save siva-sundar/18bc4c7e08656a86d73a to your computer and use it in GitHub Desktop.
Save siva-sundar/18bc4c7e08656a86d73a to your computer and use it in GitHub Desktop.
stack ovflw
import Ember from 'ember';
export default Ember.Controller.extend({
appName:'Ember Twiddle',
date: new Date(),
current_date: function() {
var d = this.get('date');
var date = '01';
var month = d.getMonth() + 1;
var year = d.getFullYear();
return {
date: date,
month: month,
year: year
};
}.property('date'),
actions: {
previousMonth: function() {
var date = this.get('date');
date.setMonth(date.getMonth() - 1);
this.set('date', date);
console.log(this.get('date'));
},
nextMonth: function() {
var date = this.get('date');
date.setMonth(date.getMonth() + 1);
this.set('date', date);
console.log(this.get('date'));
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
{{view 'myview'}}
<button {{action 'previousMonth'}}>prev </button>
<button {{action 'nextMonth'}}>next </button>
<br>
<br>
export default Ember.View.extend({
templateName: 'my-route',
date: function() {
var raw_date = this.get('controller.current_date');
return raw_date.month + " " + raw_date.year;
}.property('controller.current_date')
});
{
"version": "0.4.17",
"EmberENV": {
"FEATURES": {}
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "1.12.1",
"ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.2.0/ember-data.js",
"ember-template-compiler": "1.12.1"
}
}
export default Ember.View.extend({
templateName: 'my-route',
date: function() {
var raw_date = this.get('controller.current_date');
return raw_date.month + " " + raw_date.year;
}.property('controller.current_date')
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment