2
@AuraEnabled
public string prop { get; set;}

I need to bind above apex controller property to lightning component. Please help me on this.

2 Answers 2

6

Use a method to set the value from VF page.

@AuraEnabled

public static CLASSNAME GetProp ()

{

CLASSNAME result = new CLASSNAME();

result.prop = value;


return result;

}

In the component:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
    <aura:attribute type="CLASSNAME" name="var" />
    Value is = {!v.var.prop}
</aura:component>

In the controller:

doInit : function(cmp, ev) {
        var action = cmp.get("c.GetProp");

        action.setCallback(this, function(response) {
            var state = response.getState();
            if (state === "SUCCESS") {
                cmp.set('v.var', response.getReturnValue());
            }
            else if (state === "ERROR") {
                alert('Error : ' + JSON.stringify(errors));
            }
        });
        $A.enqueueAction(action);
    }
2

Component or App can use the controller property by using <aura:attribute/>

<aura:component>
    <aura:attribute name="prop" type="String"/>
</aura:component> 

For more information refer Lightning Components Basics Trailhead or Component Attributes

1
  • 2
    In his question, he says he's asking about an APEX controller's property, which is different than the JS property in his Lightning Controller. Might be a mistatement in his question, but clearly not the same.
    – crmprogdev
    Jan 25, 2017 at 5:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .