Namespace Usage Examples and Reference
- Components, events, and interfaces in your organization
- Custom objects in your organization
- Custom fields on standard and custom objects in your organization
- Server-side Apex controllers in your organization
- Dynamic creation of components in JavaScript
- Static resources in your organization
Organizations with No Namespace Prefix Set
The following illustrates references to elements in your organization when your organization doesn’t have a namespace prefix set. References use the default namespace, c, where necessary.
Example of a custom object or custom field in attribute defaults:
1<aura:attribute name="newExpense" type="Expense__c"
2 default="{ 'sobjectType': 'Expense__c',
3 'Name': '',
4 'Amount__c': 0,
5 …
6 }" />Example of a custom field in a JavaScript function:
1updateTotal: function(component) {
2 …
3 for(var i = 0 ; i < expenses.length ; i++){
4 var exp = expenses[i];
5 total += exp.Amount__c;
6 }
7 …
8}Example of a component created dynamically in a JavaScript function:
1var myCmp = $A.createComponent("c:myComponent", {},
2 function(myCmp) { }
3);Organizations with a Namespace Prefix
The following illustrates references to elements in your organization when your organization has set a namespace prefix. References use an example namespace yournamespace.
| Referenced Item | Example |
|---|---|
| Component used in markup | <yournamespace:myComponent /> |
| Component used in a system attribute | <aura:component extends="yournamespace:myComponent"> <aura:component implements="yournamespace:myInterface"> |
| Apex controller | <aura:component controller="yournamespace.ExpenseController"> |
| Custom object in attribute data type | <aura:attribute name="expenses" type="yournamespace__Expense__c[]" /> |
| Custom object or custom field in attribute defaults | See the example after this table. |
| Custom field in an expression | <lightning:input type="number" value="{!v.newExpense.yournamespace__Amount__c}" label=… /> |
| Custom field in a JavaScript function | See the example after this table. |
| Component created dynamically in a JavaScript function | See the example after this table. |
| Interface comparison in a JavaScript function | aCmp.isInstanceOf("yournamespace:myInterface") |
| Event registration | <aura:registerEvent type="yournamespace:updateExpenseItem" name=… /> |
| Event handler | <aura:handler event="yournamespace:updateExpenseItem" action=… /> |
| Explicit dependency | <aura:dependency resource="markup://yournamespace:myComponent" /> |
| Application event in a JavaScript function | var updateEvent = $A.get("e.yournamespace:updateExpenseItem"); |
| Static resources | <ltng:require scripts="{!$Resource.yournamespace__resourceName}" styles="{!$Resource.yournamespace__resourceName}" /> |
Example of a custom object or custom field in attribute defaults:
1<aura:attribute name="newExpense" type="yournamespace__Expense__c"
2 default="{ 'sobjectType': 'yournamespace__Expense__c',
3 'Name': '',
4 'yournamespace__Amount__c': 0,
5 …
6 }" />Example of a custom field in a JavaScript function:
1updateTotal: function(component) {
2 …
3 for(var i = 0 ; i < expenses.length ; i++){
4 var exp = expenses[i];
5 total += exp.yournamespace__Amount__c;
6 }
7 …
8}Example of a component created dynamically in a JavaScript function:
1var myCmp = $A.createComponent("yournamespace:myComponent",
2 {},
3 function(myCmp) { }
4);