I'm trying to preload my cart
model on init and am getting the error
TypeError: cart.pushPayload is not a function
I know that not all serializers have this function, but the one I am using (RESTSerializer) does. My serializer for application.js is:
import DS from 'ember-data';
export default DS.RESTSerializer.extend({});
The instance-initializer for cart.js is:
import Ember from 'ember';
export function initialize(appInstance) {
let CartService = appInstance.factoryFor('service:cart');
let payload = {
"cart": [{
"id": "S5339",
"quantity": 1,
"itemPrice": 129.95
}, {
"id": "BLK1642",
"quantity": 1,
"itemPrice": 55
}, {
"id": "TDS9004",
"quantity": 5,
"itemPrice": 99.95
}]
};
let cart = CartService.create();
cart.pushPayload(payload);
appInstance.register('cart:main', cart, { instantiate: false });
appInstance.inject('controller', 'cart', 'cart:main');
appInstance.inject('component', 'cart', 'cart:main');
}
export default {
name: 'cart',
initialize
};
For now I am using static data but if/when I get this working I will be doing a network request using ember-network.
But I'm going down the rabbit hole on why I can't get pushPayload
to work. Any help appreciated!
Aucun commentaire:
Enregistrer un commentaire