lundi 26 octobre 2015

Ember: Setting variable in template from controller

I have a variable in my template called someString that I would like to set in my controller. I am getting a Uncaught Error: Assertion Failed: TypeError: Cannot read property 'set' of undefined.

How do I make the controller aware of the template variable(if that even is the solution to this problem)?

My template looks like this:

{{#modal-dialog action="close" title="New Run"}}
  <form role="form" {{action "submit" on="submit"}}>
...
  {{input value=emailComparisonRunID class="form-control" placeholder="Comparison Run ID (optional)"}}
  <label><small>{{someString}}</small></label>
  <br>
...
  </form>
{{/modal-dialog}}

My controller looks like this:

export default Ember.ObjectController.extend({
  needs: 'services',
  dataVer: '',

  watchEmailComparisonRunId: function() {
    var comparisonId = this.get('emailComparisonRunID');
    if(comparisonId == null) {
      comparisonId = 1;
    }

    var onIdFound = function(id) {
      console.log('FOUND');
      this.set('someString', 'FOUND');
    };

    var onIdNotFound = function(reason) {
      console.log('Not Found');
      this.set('someString', 'NOT FOUND')
    };

    this.get('store').find('run', comparisonId).then(onIdFound, onIdNotFound);

  }.observes('emailComparisonRunID'),
  
  ...

  
  



Aucun commentaire:

Enregistrer un commentaire