Hosts content that uses a third-party JavaScript framework such as Angular or React. For Aura components only.
For Use In
Lightning Experience, Experience Builder Sites, Salesforce Mobile App
The lightning:container component allows you to host content developed with a third-party framework within a Lightning component. The content is uploaded as a static resource, and hosted in an iFrame. The lightning:container component can be used for single-page applications only.
This is a simple example of lightning:container, which loads an app that’s uploaded as a static resource named myReactApp.
You can also implement communication to and from the framed application, allowing it to interact with Salesforce. Use the message() function in the JavaScript controller to send messages to the application, and specify a method for handling messages with the component’s onmessage attribute.
This example defines attributes for a message to send from the container to the Lightning component and for a message received.
The client-side controller uses the message() function to send a simple JSON payload to an AngularJS app.
1({2 sendMessage: function(component, event, helper){3 var msg = {4 name: "General",5 value: component.get("v.messageToSend"),6};7 component.find("AngularApp").message(msg);8},9 handleMessage: function(component, message, helper){10 var payload = message.payload;11 var name = payload.name;12 if(name === "General"){13 var value = payload.value;14 component.set("v.messageReceived", value);15}else if(name === "Foo"){16 // A different response17}18},19});
Because you define the controller-side message handling yourself, you can use it to handle any kind of message payload. You can, for example, send just a text string or return a structured JSON response.
Usage Considerations
When specifying the src of the container, don’t specify a hostname. Instead, use $Resource with dot notation to reference your application, uploaded as a static resource.