How do I differentiate when a child LWC component is called twice in the parent component?Pass values from...
How many different ways are there to checkmate in the early game?
What is the difference between 型 and 形?
Is TA-ing worth the opportunity cost?
How to mark beverage cans in a cooler for a blind person?
Is Texas Instrument wrong with their pin number on TO-92 package?
How is this kind of structure made?
Bitcoin successfully deducted on sender wallet but did not reach receiver wallet
Why isn’t SHA-3 in wider use?
Opposite for desideratum to mean "something not wished for"
Packages "LibertinusT1Math" raises error if compiled with XeLaTeX
Which I-94 date do I believe?
Word or idiom defining something barely functional
Double redundancy for the Saturn V LVDC computer memory, how were disagreements resolved?
Write an interpreter for *
Ex-contractor published company source code and secrets online
Multirow in tabularx?
I accidentally overwrote a Linux binary file
How does "Te vas a cansar" mean "You're going to get tired"?
What costs less energy? Roll or Yaw?
How can you evade tax by getting employment income just in equity, then using this equity as collateral to take out loan?
Can a fight scene, component-wise, be too complex and complicated?
Why do oscilloscopes use SMPSes instead of linear power supplies?
changing number of arguments to a function in secondary evaluation
In a topological space if there exists a loop that cannot be contracted to a point does there exist a simple loop that cannot be contracted also?
How do I differentiate when a child LWC component is called twice in the parent component?
Pass values from parent to child component on click lightningHow to populate the selected value in dynamic picklist in lightning component?How to access aura:id of a tag present in child component in a parent component controllerLightning Components: Call init method of a child component from a parent componentHow to open LWC in a new page from Record Detail Aura ComponentError when adding different Lightning Web Components to the PlaygroundLightning Web Components: How to handle events from grand child on the owner(eventParent) componentHow to access child Web Component property from parent Aura Component controller?LWC not recognizing PageRefrence changes and not displaying updated valuesHow to setup eventListener for a LWC component to receive messages from an embedded iFrame
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ margin-bottom:0;
}
I have a parent component where I am calling a child component twice in LWC.
I am firing an API method in the child from the parent, but it is firing for only one child component, not the other one.
Parent component HTML markup
<template>
// First child component
<c-child-component><c-child component>
// Second child component
<c-child-component><c-child component>
</template>
Child @api
method
@api handleShowError{
this.showError=true
}
I have made changes in the Playground. You can check here: PlayGround
lightning lightning-web-components
add a comment |
I have a parent component where I am calling a child component twice in LWC.
I am firing an API method in the child from the parent, but it is firing for only one child component, not the other one.
Parent component HTML markup
<template>
// First child component
<c-child-component><c-child component>
// Second child component
<c-child-component><c-child component>
</template>
Child @api
method
@api handleShowError{
this.showError=true
}
I have made changes in the Playground. You can check here: PlayGround
lightning lightning-web-components
We don't have enough code to help you. As far as I can tell, this shouldn't even compile or run. Can you please create a playground that demonstrates what you're trying to achieve? Please edit the link in to your question. Thanks!
– sfdcfox
19 hours ago
@sfdcfox I have updated Playground Link. Please check it.
– sanket kumar
18 hours ago
add a comment |
I have a parent component where I am calling a child component twice in LWC.
I am firing an API method in the child from the parent, but it is firing for only one child component, not the other one.
Parent component HTML markup
<template>
// First child component
<c-child-component><c-child component>
// Second child component
<c-child-component><c-child component>
</template>
Child @api
method
@api handleShowError{
this.showError=true
}
I have made changes in the Playground. You can check here: PlayGround
lightning lightning-web-components
I have a parent component where I am calling a child component twice in LWC.
I am firing an API method in the child from the parent, but it is firing for only one child component, not the other one.
Parent component HTML markup
<template>
// First child component
<c-child-component><c-child component>
// Second child component
<c-child-component><c-child component>
</template>
Child @api
method
@api handleShowError{
this.showError=true
}
I have made changes in the Playground. You can check here: PlayGround
lightning lightning-web-components
lightning lightning-web-components
edited 25 mins ago
Peter Mortensen
2491 silver badge7 bronze badges
2491 silver badge7 bronze badges
asked 19 hours ago
sanket kumarsanket kumar
5,0662 gold badges6 silver badges29 bronze badges
5,0662 gold badges6 silver badges29 bronze badges
We don't have enough code to help you. As far as I can tell, this shouldn't even compile or run. Can you please create a playground that demonstrates what you're trying to achieve? Please edit the link in to your question. Thanks!
– sfdcfox
19 hours ago
@sfdcfox I have updated Playground Link. Please check it.
– sanket kumar
18 hours ago
add a comment |
We don't have enough code to help you. As far as I can tell, this shouldn't even compile or run. Can you please create a playground that demonstrates what you're trying to achieve? Please edit the link in to your question. Thanks!
– sfdcfox
19 hours ago
@sfdcfox I have updated Playground Link. Please check it.
– sanket kumar
18 hours ago
We don't have enough code to help you. As far as I can tell, this shouldn't even compile or run. Can you please create a playground that demonstrates what you're trying to achieve? Please edit the link in to your question. Thanks!
– sfdcfox
19 hours ago
We don't have enough code to help you. As far as I can tell, this shouldn't even compile or run. Can you please create a playground that demonstrates what you're trying to achieve? Please edit the link in to your question. Thanks!
– sfdcfox
19 hours ago
@sfdcfox I have updated Playground Link. Please check it.
– sanket kumar
18 hours ago
@sfdcfox I have updated Playground Link. Please check it.
– sanket kumar
18 hours ago
add a comment |
1 Answer
1
active
oldest
votes
this.template.querySelector
will identify only the 1st component/element. When you need to identify all the components/elements, you need to use querySelectorAll
.
You can try below:
this.template.querySelectorAll('c-child').forEach((comp) => comp.showError());
Also for more learning, you can check below links:
https://salesforcesas.home.blog/2019/07/25/lwc-access-templates-and-methods-of-child-components/
https://salesforcesas.home.blog/2019/07/16/lwc-selectors-identification-of-elements/
add a comment |
Your Answer
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "459"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f273158%2fhow-do-i-differentiate-when-a-child-lwc-component-is-called-twice-in-the-parent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
this.template.querySelector
will identify only the 1st component/element. When you need to identify all the components/elements, you need to use querySelectorAll
.
You can try below:
this.template.querySelectorAll('c-child').forEach((comp) => comp.showError());
Also for more learning, you can check below links:
https://salesforcesas.home.blog/2019/07/25/lwc-access-templates-and-methods-of-child-components/
https://salesforcesas.home.blog/2019/07/16/lwc-selectors-identification-of-elements/
add a comment |
this.template.querySelector
will identify only the 1st component/element. When you need to identify all the components/elements, you need to use querySelectorAll
.
You can try below:
this.template.querySelectorAll('c-child').forEach((comp) => comp.showError());
Also for more learning, you can check below links:
https://salesforcesas.home.blog/2019/07/25/lwc-access-templates-and-methods-of-child-components/
https://salesforcesas.home.blog/2019/07/16/lwc-selectors-identification-of-elements/
add a comment |
this.template.querySelector
will identify only the 1st component/element. When you need to identify all the components/elements, you need to use querySelectorAll
.
You can try below:
this.template.querySelectorAll('c-child').forEach((comp) => comp.showError());
Also for more learning, you can check below links:
https://salesforcesas.home.blog/2019/07/25/lwc-access-templates-and-methods-of-child-components/
https://salesforcesas.home.blog/2019/07/16/lwc-selectors-identification-of-elements/
this.template.querySelector
will identify only the 1st component/element. When you need to identify all the components/elements, you need to use querySelectorAll
.
You can try below:
this.template.querySelectorAll('c-child').forEach((comp) => comp.showError());
Also for more learning, you can check below links:
https://salesforcesas.home.blog/2019/07/25/lwc-access-templates-and-methods-of-child-components/
https://salesforcesas.home.blog/2019/07/16/lwc-selectors-identification-of-elements/
answered 18 hours ago
salesforce-sassalesforce-sas
4,3481 gold badge1 silver badge22 bronze badges
4,3481 gold badge1 silver badge22 bronze badges
add a comment |
add a comment |
Thanks for contributing an answer to Salesforce Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsalesforce.stackexchange.com%2fquestions%2f273158%2fhow-do-i-differentiate-when-a-child-lwc-component-is-called-twice-in-the-parent%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
We don't have enough code to help you. As far as I can tell, this shouldn't even compile or run. Can you please create a playground that demonstrates what you're trying to achieve? Please edit the link in to your question. Thanks!
– sfdcfox
19 hours ago
@sfdcfox I have updated Playground Link. Please check it.
– sanket kumar
18 hours ago