0

I have a model which has this field

diaryItemLabel: DS.attr('string'),

I want to access the data from this field in my controller.

Controller.js

enter image description here

I want to replace the 'Add' with whatever data I get from diaryItemLabel.

I cannot use this.get('model.diaryItemLabel'). It gives me this.get() is not a function. I tried using Ember.get('model', 'diaryItemLabel'). It gives me empty string.

Edit 1: Set default to 'Add' if model.diaryItemLabel variable is empty.

Could someone guide me to the right direction?

Thanks

user2798227
  • 853
  • 1
  • 16
  • 31

1 Answers1

1

Controller will get model property only after setupController hook which will be called after model hook.

Create computed property which dependant on model.diaryItemLabel in controller which will return your required object

confirm:Ember.computed('model.diaryItemLabel',function(){
 let temp = {};
 temp.accept= { text: Ember.isEmpty(this.get('model.diaryItemLabel')) ? 'Add' : this.get('model.diaryItemLabel'), buttonClass: 'btn btn-primary'};
 temp.reject = { text: 'cancel', buttonClass: 'btn btn-default'};
 return temp;
}
Ember Freak
  • 12,918
  • 4
  • 24
  • 54