2

I have the following in my component:

<aura:handler name="init" value="{!this}" action="{!c.doInit}"/>
<aura:attribute name="item" type="Camping_Item__c" required="true" />

Component's controller simply calls apex auraEnabled method (which is fetches one record of Camping_Item__c type) and sets v.item attribute.

When I try to run an app with this component, I get an error:

[NoErrorObjectAvailable] Aura.loadComponent(): Failed to initialize application.

If I remove required="true" from aura:attribute all goes fine.

Why is that? Is it possible to use the required="true" property with init handler?

  • Did you try by providing default value for required attribute? – Ashwani Jun 14 '16 at 20:12
  • Yes, with the default value I got the same error. – edelrabe Jun 15 '16 at 6:43
4

I am pretty sure that if you set required="true" then the app or component that declares your component needs to provide the item. For example if your component is called "Camponent" in namespace "c" then the parent app/component would need to have:

<c:Camponent item="{!v.someCampingItemThatAlreadyExists}" />

Now, if the parent's init method fills in that value, then you're fine because it won't even attempt to create the c:Camponent until the init method has finished.

  • Now it makes sense, parent app or component should provide required attribute value. I tried it and it works fine, thanks. – edelrabe Jun 15 '16 at 6:41

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.