Reputation: 6815
I'm trying to create a simple Ember-CLI app with mirage mock server. I can insert and generate random data in the database but I can't delete a record.
My application.hbs
<h2 id="title">Contacts</h2>
{{#each contact in model}}
<table>
<tr>
<td>{{contact.name}}</td>
<td>{{contact.surname}}</td>
<td>{{contact.age}}</td>
<td><button {{action 'deleteContact'}}>X</button></td> //button to delete the contact
</tr>
</table>
{{/each}}
<br>
<p>New contact</p>
{{input value=newName}}
<button {{action 'createContact' newName}}>Create contact</button>
And in application.js I define the actions
import Ember from 'ember';
export default Ember.Route.extend({
model()
{
return this.store.findAll('contact');
},
actions:
{
createContact(newName)
{
this.store.createRecord('contact',
{
name: newName
}).save();
},
deleteContact(contact)
{
return contact.destroyRecord(); // if I comment this line the error doesn't show
}
}
});
When I click the button I get this error in Ember inspector: Uncaught TypeError: Cannot read property 'destroyRecord' of undefineddeleteContact @ application.js:18triggerEvent
Upvotes: 0
Views: 786
Reputation: 18692
You have to pass contact
record instance to your action deleteContact
with signature deleteContact (contact)
.
<button {{action 'deleteContact' contact}}>X</button></td>
Upvotes: 1