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

1 Answer 1

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;
}
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks @kumkanillam
Also can you tell me how do I set the temp.accept text default to 'Add'. So if model.diaryItemLabel is empty, then set it to 'Add'
Updated answer with isEmpty check . emberjs.com/api/classes/Ember.html#method_isEmpty
I think your Edit is better than mine, so I will let it be. Thanks for your time and effort

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.