Activity Forums Salesforce® Discussions How can we use same aura:id for multiple Salesforce lightning tags in a component?

  • Deepak

    Member
    December 11, 2019 at 2:43 pm

    Presuming that you're dynamically creating components (e.g. c1 and c2), you have total control over the aura:id. A component cannot define its own aura:id, only the aura:id for children within itself. From here, it follows that you're trying to figure out what type of component you're dealing with. For that, we use Component#getType. This tells you exactly what type of component you're dealing with.

    For example:

    var c2 = component.find("child2");
    if(c2.getType() === "c:someComponent") { ...
    Alternatively, if you're exposing actual aura:method references, you can also check for the presence of the function before calling it:

    var c2 = component.find("child2");
    if(c2.someMethod) { ...
    Finally, if you are using interfaces, you can also check if a component is a type of interface:

    if(c2.isInstanceOf("c:interfaceName")) { ...

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos