0
votes

I am creating lightning component dynamically. On callback, I am facing a strange error which should not come.

 $A.createComponent(
            "c:TestComponent",
            {
                parameter1 : "hey"
            },
            function(newComponent, status){
                    var con = component.find('container');
                    if (component.isValid() && con.isValid() && status === 'SUCCESS') {
                        var body = con.get("v.body");
                        body.push(newComponent);
                        con.set("v.body", body);
                    }                
            });

and .cmp file I have

<div aura:id="container" class="slds-align-top"> 
</div>

and I am getting error in if condition.

con.isValid is not a function

Since container itself is not valid, I am not able to read the body of container where I want to include newly created component? What is wrong?

1
Can u make a debug on con? So do u get any results? Have u also inspect the html code if this id is set correct? Can you please provide the whole function? - utm

1 Answers

0
votes

I Have just change the code please check on your end

$A.createComponent(
            "c:TestComponent",
            {
                parameter1 : "hey"
            },
            function(newComponent, status){

                    if (component.isValid()  && status === 'SUCCESS') {
var con = component.find('container');
                        var body = con.get("v.body");
                        body.push(newComponent);
                        con.set("v.body", body);
                    }                
            });

thanks Dillip