Trouble dynamically creating a custom lightning component (non aura component)

I’m trying to dynamically create a custom component and insert it into the body of another one. That component (CaseComponent) has a Case attribute. The trouble is that the Case attribute is never filled, and I get an error when I try to reference the Case’s fields, such as the CaseNumber.

Here is the Case Component:

<aura:component>
<aura:attribute type="Case" name="case"/>
<div class="case">
    <p class="textCenter caseNumber">{!case.CaseNumber}</p>
    <p>Status: {!case.Status}</p>
    <p>Subject: {!case.Subject}</p>
</div>

Here is the javascript controller that tries to make this component dynamically.

$A.createComponent(
"c:CaseComponent",
{
    "case": testCase,
},
function(newCaseList){
    if (component.isValid()) {
        var body = component.get("v.body");
        body.push(newCaseList);
        component.set("v.body", body);
    }
});

I’m getting the following error message

“Assertion Failed!: Unable to get value for key ‘case.CaseNumber’. No
value provider was found for ‘case’. : false. Please try again.”

If anyone has any idea as to what I could be doing wrong for this not to work, it would be much appreciated.

Answer

Your logic is right, but your syntax is incorrect. Try changing {!case.CaseNumber} to {!v.case.CaseNumber} and do the same for the others.

Attribution
Source : Link , Question Author : Hassan , Answer Author : Vamsi Krishna Gosu

Leave a Comment