12

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.

11

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

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.