vendredi 14 octobre 2016

Ember.js - How to properly call the store from a controller?

so I am trying to access the store from a controller like so:

import Ember from 'ember';

export default Ember.Controller.extend({
  emailAddress: '',
  message: '',

  isValidEmail: Ember.computed.match('emailAddress', /^.+@.+\..+$/),
  isMessageLongEnough: Ember.computed.gte('message.length', 10),

  isValid: Ember.computed.and('isValidEmail', 'isMessageLongEnough'),
  isNotValid: Ember.computed.not('isValid'),

  actions: {

    sendConfirmation() {
      this.store.createRecord('contact', {
        email: emailAddress,
        message: message,
      }).save();

      this.set('responseMessage', 'We got your message and we will be in contact soon :)');
      this.set('emailAddress', '');
      this.set('message', '');
    }
  }

});

I looked at the documentation for Ember.js 2.7 and it doesn't specifically tell you where one can have access to the store, but I know it can be access it through a controller or route.

However, doing it this way gives me these errors:

controllers/contact.js: line 17, col 16, 'emailAddress' is not defined.
controllers/contact.js: line 18, col 18, 'message' is not defined.

I'm not sure if it's the way I am accessing the controller, or the way I defined emailAddress and message.

Please help and thank you!




Aucun commentaire:

Enregistrer un commentaire