Hi there, I'm currently working on a project where I need to add an object to an array using Ember. The friends controller model contains an array of objects (App.friends).
In the friends/new template, I collect a user's first name, last name, and some information about them.
Once I have gathered this information, the user clicks "create" and the details are added to App.friends by utilizing the needs feature in Ember to access App.friends from within the FriendsNewController.
However, when I attempt to create the object, I encounter the following error:
Uncaught TypeError: desc.get is not a function
App.FriendsRoute = Ember.Route.extend({
model: function(){
return App.friends;
}
});
App.FriendsNewController = Ember.Controller.extend({
needs: 'friends',
isInvalid: true,
validForm: function(){
if(this.get('lastName') && this.get('firstName')){
this.set("isInvalid", false);
} else {
this.set("isInvalid", true);
}
}.observes('firstName', 'lastName'),
actions: {
create: function(){
var newFriend = Ember.copy(this.content);
this.get('controllers.friends.model').addObject(newFriend);
this.transitionToRoute('friends');
}
}
});
<script type="text/x-handlebars" id="friends/new">
<label>First Name</label>
{{input value=firstName}}<br />
<label>Last Name</label>
{{input value=lastName}}<br />
<label>About</label>
{{textarea value=about}}<br />
<button {{action "create"}} {{bind-attr disabled=isInvalid}}>Create</button>
</script>
App.friends = [
{id: 1, firstName: "John", lastName: "Joe", about: "Funny"},
{id: 2, firstName: "Mary", lastName: "Joey", about: "Smart"},
{id: 3, firstName: "Henry", lastName: "Jim", about: "Kind"}
];
I am quite new to Ember, so any guidance or advice would be greatly appreciated. Thank you :)