0
votes

I have model mailbox with collectionAction

import DS from 'ember-data'
import { collectionAction } from 'ember-api-actions'

export default DS.Model.extend({
  mailbox: DS.attr(), //display only
  pin: DS.attr(),
  download: collectionAction({ path: 'greeting'})
})

and when i try to call download from my component i get an error

import Component from '@ember/component'
import Ember from 'ember'
import FileSaverMixin from 'ember-cli-file-saver/mixins/file-saver'

export default Component.extend(FileSaverMixin, {
  hifi: Ember.inject.service(),
  notifications: Ember.inject.service('notification-messages'),
  startPlay: true,
  changeset: {},
  actions: {
    toggle () {
      let hifi = this.get('hifi')
      if (this.get('startPlay')){
        this.set('startPlay', false )
        this.get('changeset').get('download')().then((content) => {
          this.saveFileAs(this.get('filename'), content, this.get('contentType'))
          })
        this.get('play')()
      } else {
        hifi.togglePause();
      }
    },
  }
})

The error is Uncaught TypeError: Cannot read property 'constructor' of undefined. I check my cod/ It is the same like ember-api-actions But my cod did not work. Please help me. I don't understand what is wrong.

2

2 Answers

1
votes

It was a trouble with using ember-changeset addon. When i put the model in my component instead of changeset model, all works fine. Thank you Paul for your efforts to help me. Question solved.

0
votes

Based on what I can tell from your post, it seems .get('download')() is not the correct method to call the collectionAction. This may be all or part of your issue. You should be able to do so by using the below:

this.get('change').download().then(() => {});