0

JS of ProductList Component

import { LightningElement, api, track, wire } from "lwc";
import getProducts from '@salesforce/apex/reviewsController.getProducts';
// import productDetails from '@salesforce/apex/reviewsController.productDetails';
import { NavigationMixin } from 'lightning/navigation';
export default class ProductsList extends NavigationMixin(LightningElement) {
    @wire(getProducts) wiredgetProducts;
    @track clickedButtonLabel;

    //call method start
    @api searchKey = '';
    // @wire(productDetails, { searchKey: '$searchKey' })
    // wiredproductDetails;
    handleClick(event) {
        this.clickedButtonLabel = event.target.label;
    }
    navigateToProdDetailPage(event) {
        this.searchKey = event.target.dataset.id;
        console.log('this.searchKey', this.searchKey);

        // Navigate to a URL
        this[NavigationMixin.Navigate]({
            type: 'comm__namedPage',
            attributes: {
                name: 'productdetailspage__c',
                actionName: 'view',
            }
        },
            // true // Replaces the current page in your browser history with the URL
        );
    }
}

JS of Product Detail

import { LightningElement, api, track, wire } from "lwc";
import productDetails from '@salesforce/apex/reviewsController.productDetails';
export default class ProductDetails extends LightningElement {
    @wire(productDetails, { searchKey: '$searchKey' })
    wiredproductDetails;
}

2 Answers 2

2

If you want to pass data between two unrelated component

Condition 1 : If both component are in same lightning app. then you can use Expose Event in LWC

https://www.forcetrails.com/2021/08/publish-lwc-events-to-lightning-app-builder.html

Note: you can use pubsub as well

Condition 2: If both component are in different lightning app. the you can use LMS

1
  • 1
    It is best to use Salesforce terminology - here "dynamic interactions" - and to link to the official documentation.
    – Phil W
    Nov 16, 2022 at 8:52
1

If you want to pass data between two unrelated component you can use LMS(Lightning message Service) to achieve it.

Attaching a link to the standard document from where you can get much better understanding of LMS.

1
  • 1
    IMHO this is more of a comment than an answer. The answer should provide more about the rationale, give an example against the provided code if that's not too complex to do and/or quote and link to the official Salesforce documentation.
    – Phil W
    Nov 16, 2022 at 8:51

You must log in to answer this question.

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