Skip to content

Instantly share code, notes, and snippets.

@phillipkregg
Created April 5, 2018 15:39
Show Gist options
  • Save phillipkregg/f82cc5f5156f249565cddf2fa491a6cc to your computer and use it in GitHub Desktop.
Save phillipkregg/f82cc5f5156f249565cddf2fa491a6cc to your computer and use it in GitHub Desktop.
Call Route from Controller - Refresh Model
import Ember from 'ember';
export default Ember.Controller.extend({
appName: 'Ember Twiddle',
newFood: '',
actions: {
testing() {
this.send('testingRoute', this.get('newFood'));
}
}
});
import Ember from 'ember';
export default Ember.Route.extend({
testModel:['tacos', 'burritos', 'ice cream'],
model() {
return this.get('testModel');
},
actions: {
testingRoute(newFood) {
// Make db call to persist model from here if necessary
this.get('testModel').pushObject(newFood);
//this.refresh();
}
}
});
body {
margin: 12px 16px;
font-family: 'Helvetica Neue', Helvetica, Arial, sans-serif;
font-size: 12pt;
}
<h1>Welcome to {{appName}}</h1>
<br>
<br>
{{outlet}}
<br>
<br>
<label>Enter New Food</label>
{{input type="text" value=newFood}}
<ul>
{{#each model as |food|}}
<li>{{food}}</li>
{{/each}}
</ul>
<button {{action 'testing'}}>Call route method from template</button>
{
"version": "0.13.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.16.2",
"ember-template-compiler": "2.16.2",
"ember-testing": "2.16.2"
},
"addons": {
"ember-data": "2.16.3"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment