6

The following code fails:

$A.createComponent(
        "aura:HTML",
         { tag: "div",
         body: 'value',
         HTMLAttributes:{"id": "Temp","class": "class name here"}
         },
        function(newCmp, status, errorMessage){
            var container = component.find('root');
            if (container.isValid() && newCmp!= null) {
                var body = container.get("v.body");
                body.push(newCmp);
                container.set("v.body", body);
            }
        }
    );

Error:

 render threw an error in 'markup://aura:html' [Assertion Failed!: Descriptor for Config required for registration : undefined] Failing descriptor: {markup://aura:html}

And the same code without "body: 'value'" creates div block:

$A.createComponent(
        "aura:HTML",
         { tag: "div",
         HTMLAttributes:{"id": "Temp","class": "class name here"}
         },
        function(newCmp, status, errorMessage){
            var container = component.find('root');
            if (container.isValid() && newCmp!= null) {
                var body = container.get("v.body");
                body.push(newCmp);
                container.set("v.body", body);
            }
        }
    );

Also I tried to set body after component was created:

newCmp.set("v.body", 'value');

Also got error.

5

You should use aura:html instead of aura:HTML . Always remember everything in lightning is case-sensitive.

Here's the sample code which I tried in my org.

myApp.app:

<aura:application access="global">
    <div aura:id="root"></div>
    <button type="button" onclick="{!c.createDivCmp}">Creat Div</button>
</aura:application>

myAppController.js

({
    createDivCmp : function(component,event,helper) {
        $A.createComponent(
            "aura:html",
            { tag: "div",
                body: 'value',
                HTMLAttributes:{"id": "Temp","class": "class name here"}
            },
            function(newCmp, status, errorMessage){
                var container = component.find('root');
                if (component.isValid() && container.isValid() && status === 'SUCCESS') {
                    var body = container.get("v.body");
                    body.push(newCmp);
                    container.set("v.body", body);
                }
            }
        );
    }
})
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.