Skip to content

Instantly share code, notes, and snippets.

@hotsoft-desenv4
Last active May 28, 2020 23:53
Show Gist options
  • Save hotsoft-desenv4/6b19fae4cb32ad19725b4cdaf8cce5f8 to your computer and use it in GitHub Desktop.
Save hotsoft-desenv4/6b19fae4cb32ad19725b4cdaf8cce5f8 to your computer and use it in GitHub Desktop.
//app/components/marcas/marcas-form.js
import Component from '@ember/component';
export default Component.extend({
//https://guides.emberjs.com/v3.3.0/components/triggering-changes-with-actions/
//https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/closure-actions.md
actions: {
saveMarca(marca) {
let selfthis = this;
marca.save().then( function() {
selfthis.sendAction('redirectTo');
});
}
}
});
//app/routes/marcas/new.js
import Component from '@ember/component';
export default Component.extend({
actions: {
deleteMarca(marca) {
marca.destroyRecord();
}
}
});
{{!--app/templates/marcas/new.hbs --}}
<h2>Criar nova marca</h2>
{{!-- https://github.com/ember-cli/eslint-plugin-ember/blob/master/docs/rules/closure-actions.md --}}
{{marcas/marcas-form
model="model"
redirectTo=(action "redirectTo")
}}
//app/routes/marcas/new.js
import Route from '@ember/routing/route';
export default Route.extend({
model() {
return this.store.createRecord('marca');
},
//https://guides.emberjs.com/v1.12.0/components/sending-actions-from-components-to-your-application/
actions: {
redirectTo: function() {
this.transitionTo("marcas");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment