Hi.I am new to ember.I’ve been following a tutorial, and something about actions bugged my mind.There is an ‘index’ template.Which doesn’t have a model.Tutorial used a controller for ‘saveInvitation’ action.
{{input type="email" value=emailAddress"}}
<button type="submit" {{action 'saveInvitation' }}></button>
---Corresponding contoller code snippet below---
actions: {
saveInvitation() {
const email = this.get('emailAddress');
const newInvitation = this.store.createRecord('invitation', { email: email });
newInvitation.save();}
Then, later on, there is an object, which doesn’t have a controller, and the action goes on rotues file.But this time, ‘model.value’ attribute is passed.
{{input type="text" value=model.name class="form-control" placeholder="The name of the Library"}}
<button type="submit" {{action 'saveLibrary' model}}>Add to library list</button>
----Corresponding code snippet in ROUTEs file below ----
actions: {
saveLibrary(newLibrary) {
newLibrary.save().then(() => this.transitionTo('libraries'));
}
It doesn’t make sense to me, why do we add ‘model.’ to objects properties in input fields.Also why the way we define the action has changed.Shouldn’t it be like this:
actions: {
const property1 = this.get('property1');
const property2 = this.get('property2');
and so on...
const newLibrary=this.store.createRecord('library', {properties: values}).save();}