gokatz
10/5/2016 - 10:30 AM

component binding

component binding

{
  "version": "0.10.5",
  "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.8.0",
    "ember-data": "2.8.0",
    "ember-template-compiler": "2.8.0",
    "ember-testing": "2.8.0"
  },
  "addons": {}
}
<li>{{num}}</li>

{{canShow}}
<br>
<button {{action 'toggleShow'}}>Toggle</button>
<hr>
<h1>Welcome to {{appName}}</h1>
<br>
{{arr.0.a}}
{{arr.1.a}}
{{arr.2.a}}
<button {{action 'resetArr'}}> Reset </button>
<hr>
{{#each arr as |num|}}
{{num.a}}
{{my-comp canShow=canShow num=num.a}}
{{/each}}
<hr>
{{canShow}}
<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';

export default Ember.Controller.extend({
  appName: 'Ember Twiddle',
  arr : [
    {a: 1, b: 2},
    {a: 1, b: 2},
    {a: 1, b: 2},
  ],
  canShow: false,
  
  actions: {
  	resetArr() {
    	this.set('arr', [
    {a: 1, b: 2},
    {a: 1, b: 2},
    {a: 1, b: 2},
  ]  );
      this.set('canShow', false);
    }
  }
});
import Ember from 'ember';

export default Ember.Component.extend({
  actions: {
  	toggleShow() {
      console.log('triggered');
      this.set('num', 4);
    	this.set('canShow', true);
    }
  }
});