1

I'm trying to make a link dynamically using $A.createComponents but it tends to refresh the page even if I use

javascript:void(0)

Previously this was working fine but in the latest release this is giving a problem.

$A.createComponents([

                            ["aura:html",{
                                "tag" : "a",
                                "HTMLAttributes" : {"id":"" ,
                                                    "class": "",
                                                    "href":"'javascript:void(0);'"
                                                   }
                            }],
                            ["aura:html",{
                                "tag" : "label",
                                "body":"",
                                "HTMLAttributes" : {"id":"" ,
                                                    "onclick":""
                                                   }
                            }],
                            ["aura:html",{
                                "tag" : "span",
                                "HTMLAttributes" : {"id":"",
                                                    "onclick":""
                                                   }
                            }]

                        ],
                                            function(components, status, errorMessage){


                                                if (status === "SUCCESS") {
                                                    var a = components[0].get("v.body");
                                                    a.push(components[1]);
                                                    a.push(components[2]);
                                                    components[0].set("v.body", a);

                                                    var container = component.find("aaa");
                                                    var body = container.get("v.body");
                                                    body.push(components[0]);
                                                    container.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
                                                    }
                                            }
                                           );

1 Answer 1

0

I am new in Lightning, but as per my understanding you can achieve your requirement via :

["aura:html",{
   "tag" : "a",
   "HTMLAttributes" : {"id":"" ,
                    "class": "",
                    "onclick": component.getReference("c.handleClick")
                   }
}],

And handleClick method would be like:

 ({
   handleClick: function (component, event, helper) {
     event.stopPropagation();
  }
})
3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .