Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save kumkanillam/88419980e4686f2eaaf572673fa36127 to your computer and use it in GitHub Desktop.
Save kumkanillam/88419980e4686f2eaaf572673fa36127 to your computer and use it in GitHub Desktop.
New Twiddle
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
myService: Ember.inject.service()
});
import Ember from 'ember';
export default Ember.Service.extend({
foo() {
let worked = this.toString().match(/service/);
if (worked) {
alert('foo method called correctly');
} else {
alert('foo method called with incorrect context');
}
},
actions: {
bar() {
let worked = this.toString().match(/service/);
if (worked) {
alert('bar action called correctly');
} else {
alert('bar action called with incorrect context');
}
}
}
});
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<button {{action myService.foo}}>Incorrect 'this'</button>
<button onclick={{action myService.foo}}>Incorrect 'this'</button>
<button {{action myService.foo target=myService}}>Works setting target</button>
<button onclick={{action myService.foo target=myService}}>Incorrect 'this'</button>
<button {{action 'foo' target=myService}}>Works for function on object</button>
<button {{action 'bar' target=myService}}>Does not work for actions hash</button>
<button onclick={{action 'bar' target=myService}}>Works for function in actions hash</button>
{{!-- <button onclick={{action 'foo' target=myService}}>Does not work for action on object - causes template render error</button> --}}
{
"version": "0.10.6",
"EmberENV": {
"FEATURES": {}
},
"options": {
"use_pods": false,
"enable-testing": false
},
"dependencies": {
"jquery": "https://cdnjs.cloudflare.com/ajax/libs/jquery/1.11.3/jquery.js",
"ember": "release",
"ember-template-compiler": "release",
"ember-testing": "release"
},
"addons": {}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment