function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
tulasiram chtulasiram ch 

getting error like below please help me...I am learning lightning

harnessApp.app:
  1. <aura:application >
  2.     <c:campingListItem item="{!v.a0d2800000DTLYOAA5}"/>
  3. </aura:application>
campingListItem.cmp:
  1. <aura:component >
  2.     <aura:attribute name="item" type="Camping_Item__c" required="true"/>
  3.     <p> The Item is <ui:outputText value="{!v.item}"></ui:outputText></p>
  4.     <p>Name:<ui:outputText value="{!v.item.Name}" />  </p>
  5.     <p>Price: <ui:outputCurrency value="{!v.item.Price__c}" /> </p>
  6.     <p>Quantity:<ui:outputNumber value="{!v.item.Quantity__c}" /> </p>
  7.     <p>Packed:<ui:outputCheckbox value="{!v.item.Packed__c}" />  </p>
  8.    <div><ui:button label="Packed!" press="{!c.packItem}"/>
  9.    </div>
  10. </aura:component>
harnessAppController.js:
  1. ({
  2.      packItem: function(component, event, helper) {
  3.         var btn= event.getSource();
  4.         var BtnMessage =btn.get("v.label");
  5.         component.set("v.item",BtnMessage);
  6.         var btnClicked = event.getSource();
  7.         btnClicked.set("v.disabled",true);     
  8.      }
  9. })
User-added imageUser-added image
But i am getting above error when click on the button packed!.....
Pramodh KumarPramodh Kumar
Hi tulasriram,


In your app the calling the component syntax is wrong.

<c:campingListItem item="{!v.a0d2800000DTLYOAA5}"/> in this line you need to pass the Camping_Item__c type object, instead you are passing the a attribute "a0d2800000DTLYOAA5" which is not available in your harnessApp.app

if you are passing a record Id, it doesn't understand the type value more over when you have to get the object information in order to pass to the child component. Please go through the attributes trailhead. Make sure you understand the purpose of the attribute

the correct syntax would be 
<aura:attribute name="newExpense" type="Expense__c" default="{ 'sobjectType': 'Expense__c', 'Name': '', 'Amount__c': 0, 'Client__c': '', 'Date__c': '', 'Reimbursed__c': false }"/>
<c:campingListItem item="{!v.newExpense}"/>

let me know if you have any question.

Thanks,
Pramodh
Shubham Prajapati 19Shubham Prajapati 19
In addition to the answer given by @Pramodh, elements of a component can only call actions contained in the controller of the same component bundle. In your code on press event of  <ui:button label="Packed!" press="{!c.packItem}"/>, you are calling to the action contained in the harnessApp. You should create campingListItemController.js like this 
({
     packItem: function(component, event, helper) {
        //write your logic    
     }
})