Hi Folks, In this blog we will try to understand, How we can Add a Property to each Object in an Array of Objects with JS in LWC.
Lets suppose we have an array as given below:-
let contactData=[
{Name:'Rahul',Age:'31',CreditScore:750},
{Name:'Rogers',Age:'28',CreditScore:640} ];
Now let takes a requirement, that if the credit score is more than or equals to 700 then the rating should be 'Hot' or if it is less than the 700 rating should be 'Cold' and then add this property to every object of the Array of Objects that we have. And final output will look like as given below:
Hi Folks, In this blog we will try to understand how we can call child LWC methods in parent LWC using querySelector
The querySelector()method is a standard DOM API that returns the first element that matches the selector.
Parent component can invoke a child component’s public method as well, for this to work declare the method as public in child using @api annotation
In this example child LWC exposes increaseCounter(), decreaseCounter(), methods by adding the @api decorator to the methods. A parent component that contains c-child ( i.e. our child LWC) can call these methods.
The handleIncrease() function in parent LWC calls the increaseCounter() method in the c-child element. this.template.querySelector('c-child') returns the c-child element in parent.html. The this.template.querySelector() call is useful to get access to a child component so that you can call a method on the component.
The handleDecrease() function in parent LWC calls the decreaseCounter() method in the c-child element.
Hi Folks, In this blog we will try to understand how we can use the navigation service, Lightning/Navigation, to navigate to many different page types, such as record, list view, object and lightning component.
To use the navigation service, we should import the lightning/navigation module in the component’s JavaScript class.