ember.jshandlebars.jsember-dataember.js-3

Ember load variable everytime page is loaded


I want a variable called "name" in my router or controller , which i will use in my hbs template. Right now , I'm doing this. But the get() is not loading if i navigate backward and click the link to the current page again. It only loads the first time and if i refresh the page . Due to this, the value of name in my form is not reloading everytime i hit the page.

      #controller
      name: computed('model.name', {
        get() {
          return this.get('model.name');
        }
      })



      #.hbs
      {{input type = "text" value=name }}
      <button {{action 'update' model.id }}>Update Post</button> 


        #routefile
      import Route from '@ember/routing/route';
      import EmberObject, { computed } from '@ember/object';
      export default Route.extend({
      model(params) {
       return this.get('store').findRecord('post',params.post_id );
      }
      });

Solution

  • You need to add a set method, as otherwise the computed property that you've declared, will be overridden by the value of the input (via the {{input}} helper).

      name: computed('model.name', {
        get() {
          return this.get('model.name');
        },
        set(key, value) {
          return value;
        }
      })