gokatz
2/19/2016 - 6:48 AM

mixin inj

mixin inj

{
  "version": "0.5.3",
  "EmberENV": {
    "FEATURES": {}
  },
  "options": {
    "enable-testing": false
  },
  "dependencies": {
    "jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
    "ember": "1.13.13",
    "ember-data": "https://cdnjs.cloudflare.com/ajax/libs/ember-data.js/2.3.3/ember-data.js",
    "ember-template-compiler": "1.13.13"
  }
}

<button {{action 'testAction'}}>Ping Us (From Component)</button>
import Ember from 'ember';

export default Ember.Service.extend({
  name: 'CodeX',
  product: ['mobile software', 'web development', 'wed design']
});
import Ember from 'ember';

const arr = [1,2,3];

let mixin = Ember.Mixin.create({
	product: ['mobile software', 'web development', 'wed design'], 
  contact: 'gokul@codex.com',
  
  actions: {
  	testAction() {
      console.log(arr);
    	alert('hai');
    }
  }
});

export default mixin;
export default {
  name: 'currentUser',
  initialize: function(container, application) {
    application.inject('controller', 'appname', 'service:appname');
    //application.inject('controller', 'apptest', 'mixin:apptest');
  }
};
import Ember from 'ember';

export default Ember.Component.extend({
  actions:{
  	testAction() {
    	this.attrs.testAction();
    }
  }
});
<h1>Welcome to {{appName}}</h1>
<br>
<h3>Handling Projects Under </h3>
{{#each products as |product|}}
<li>{{product}}</li>
{{/each}}
<br>
contact us @ {{contactdetails}}

{{my-compo testAction=(action 'testAction')}}
<hr>
<button {{action 'testAction'}}>Ping Us (In Template)</button>
<button {{action 'accessGlobalFromMixin'}}>Global Access (In Template from Mixin)</button>

<br>
{{outlet}}
<br>
<br>
import Ember from 'ember';

import testMixin from 'twiddle/mixins/apptest';

export default Ember.Controller.extend(testMixin, {
  appName: Ember.computed(function() {
  	return this.get('appname.name'); //service injected
  }),
  products: Ember.computed(function() {
  	return this.get('apptest.product'); //mixin injected => wrong
  }),
  contactdetails: Ember.computed(function() {
  	return this.get('apptest.contact');  //mixin injected => wrong
  }),
  
  actions: {
  	accessGlobalFromMixin() {
    	console.log(arr);
    }
  }	
});