0

I dynamically created a preexisting component to render in a modal layered above my "parent" component. I passed in attributes and everything functions great but upon a button click in the parent component, i'd like to fire a method in the dynamically created component (as well as a method in the parent controller)

here is my code for the dynamically created component. I can add more but as this seemed more of a structure question and not a bug question i dont know if its relevant

createAComponent : function (cmp, event, helper) {
    $A.createComponent(
        "c:uploadSorter",
        {
            "aura:id": "findableAuraId",
            "policyrecordID": cmp.get("v.recordId"),
            "fileId": cmp.get("v.fileId"),
            "handleNavigate": cmp.getReference("c.handleClick")


        },

                        //"onclick": cmp.getReference("c.handlePress")
        function(newUploader, status, errorMessage){
            //Add the new button to the body array
            if (status === "SUCCESS") {
                var body = cmp.get("v.body");
                body.push(newUploader);
                cmp.set("v.body", body);
            }
            else if (status === "INCOMPLETE") {
                console.log("No response from server or client is offline.")
                // Show offline error
            }
            else if (status === "ERROR") {
                console.log("Error: " + errorMessage);
                // Show error message
            }
        }
    );

I am thinking an event handler so I am fumbling around with those but any advice would be greatly appreciated

  • if you want to fire a method from the parent component, you will have to use an event, cmp.getReference is to reference a method at the same level (in thos case, from the created component) – glls Apr 16 at 18:21
  • thanks, yeah i shouldnt have left that in there. that was from an initial attempt and ran into the issue you are mentioning in that it fires up to the parent, not down to the child – Bobbygllh Apr 16 at 18:22
  • i'm not quite sure what your question is then, is it, "should i use an event" ? if so, the answer is yes – glls Apr 16 at 18:24
  • yes that is the question – Bobbygllh Apr 16 at 18:26
1

Just validating that yes, you should be using an event to fire the method from the parent container.

you will still be referencing the method using cmp.getReference("c.handlePress")

and from your handlePress method, fire the event in which the parent component should have a handler.

  • Nevermind. Deleted this comment as i figured out what i was asking. Thank you – Bobbygllh Apr 16 at 19:33
  • you probably want to open a new post for event firing related issues - comments are not for extended discussions or follow up questions related to the original post =) – glls Apr 16 at 19:36
  • i would rather not – Bobbygllh Apr 16 at 19:36
  • well..this is how this forum works - 1 question, 1 answer. otherwise we would end up with huge threads under anwers in posts, and for those that do that, its impossible to search for others facing similar or the same issue. – glls Apr 16 at 19:38

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.