gokatz
5/24/2016 - 1:36 PM

Obs and Comp

Obs and Comp

{
  "version": "0.8.1",
  "EmberENV": {
    "FEATURES": {}
  },
  "options": {
    "use_pods": false,
    "enable-testing": false
  },
  "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "2.5.1",
    "ember-data": "2.5.2",
    "ember-template-compiler": "2.5.1"
  }
}
<h1>Welcome to {{appName}}</h1>
{{isNameChanged}}
<br>
NAME: {{name}}
<br>
AGE: {{age}}
<br>
HEIGHT: {{height}}
<br>
<hr>
COUNT: {{count}}
<br>
<button {{action 'changeVal'}}>Change</button>
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle',
  count: 0,
  name: 'gokul',
  age: 20,
  height: 6,
  isNameChanged: Ember.computed('name', 'age', 'height', function() {
  	console.log('Computed');
    alert('Computed');
    var newCount = this.get('count')+1;
  	this.set('count', newCount);
  }),
  
  isNameObservered: Ember.observer('name', 'age', 'height', function() {
    console.log('Observer');
    //var newCount = this.get('count')+1;
  	//this.set('count', newCount);
  }),
  actions: {
  	changeVal() {
    	this.set('name', `${Math.floor((Math.random() * 10) + 1)}`);
      this.set('age', `${Math.floor((Math.random() * 10) + 1)}`);
      this.set('height', `${Math.floor((Math.random() * 10) + 1)}`);
    }
  }
});