NoFuchsGavin NoFuchsGavin - 8 days ago 5
Javascript Question

How to get a value with argument/flag from controller

I want to get the property defined in my controller. I do need a property, cause I am using it also in a template.

My Implementation:

export default Ember.ObjectController.extend({
canNotSave: function(lookup) {
console.log(lookup);
if(lookup === true) {
//.... DO SOMETHING
return true;
}
else {
return false;
}
}.property(),

actions: {
close: function() {
var canNotSave = this.get('canNotSave',true); //<- This is not working
if(canNotSave)
{
//.... DO SOMETHING
}
}
},
});


Is this possible to do something like this? And how?

GUL GUL
Answer

I think you can do something like this:

export default Ember.ObjectController.extend({
    lookup: null,
    canNotSave: Ember.computed("lookup", function() {
        if(this.get("lookup")) {
            //.... DO SOMETHING
            return true;
        }
        else {
            return false;
        }
    }),

    actions: {
        close: function() {
          this.set("lookup", true);
          if(this.get("canNotSave")) {
            //.... DO SOMETHING
          }
        }
    },
});