How could I push an item into an array in this case.
//controlle/product.js
import Controller from ‘@ember/controller’;
export default Controller.extend({
appName: “ShoppingCart”,
products: [],
action: {
add() {
this.get('products').pushObject(this.get('product'));
}
}
});
//template/product.js
I am Product
{{appName}}
{{#each model as | product|}}
{{product.title}}
{{product.owner}}
{{product.city}}
<button {{action 'add' product}}>Add</button>
-
{{#each products as |product index| }}
- {{product}}(remove) {{/each}}
{{outlet}}
//router/product.js import Ember from ‘ember’;
export default Ember.Route.extend({ model() { return [{
id: 1,
title: 'Grand Old Mansion',
owner: 'Veruca Salt',
city: 'San Francisco',
}, {
id: 2,
title: 'Grand Old Mansion',
owner: 'Veruca Salt',
city: 'San Francisco',
}, {
id: 3,
title: 'Grand Old Mansion',
owner: 'Veruca Salt',
city: 'San Francisco',
}, {
id: 4,
title: 'Grand Old Mansion',
owner: 'Veruca Salt',
city: 'San Francisco',
}];
}
});