Lightning creation of UI components dynamically (programmatically) failed We created a component with .cmp file with a section below:
<div aura:id="ElementHere"></div>
Then in the Helper JS class, we want to create ui:inputText
control dynamically and place them at the div with aura:id="ElementHere":
createInputText : function(cmp, textLabel) {
var componentConfig = {
"componentDef": "markup://ui:inputText",
"attributes": {
"values": { label:textLabel, size:10, default:"enter text" }
}
};
$A.componentService.newComponentAsync(
this,
function(newInputText){
var divComponent = cmp.find("ElementHere");
var divBody = divComponent.get("v.body");
divBody.push(newInputText);
divComponent.set("v.body", divBody);
},
componentConfig
);
},
When we ran the app, we got a pop-up that complained that divComponent does not have get method.
Does anyone know if this is a bug, or we have missed some steps?
createInputText
js function? It needs to be attached to some event as an event handler for it to work. Where is that code?