1
<aura:component
implements=
"force:appHostable,flexipage:availableForAllPageTypes"
>
2
3
<ui:button
label=
"Navigate to C1"
press=
"{!c.Navigate}"
/
4
5
{!v.body}
6
7
</aura:component
01
({
02
Navigate : function(component, event, helper) {
03
$A.createComponent(
04
"c:C1"
,
05
{
06
07
},
08
function(newCmp){
09
if
(component.isValid()) {
10
var body
=
component.
get
(
"v.body"
);
11
body.push(newCmp);
12
component.set(
, body);
13
}
14
15
16
17
18
})
Component C
Successfully Loaded ! ! !
<aura:component access="global" implements="force:appHostable"> <aura:handler name="init" value="{!this}" action="{!c.doInit}" /> <aura:handler event="c:navigateToCmp" action="{!c.NavigateComponent}" /> <div> {!v.body} </div> </aura:component>
doInit : function(component, event, helper) { $A.createComponent("c:studys", { }, function(newCmp) { if (component.isValid()) { component.set("v.body", newCmp); } }); }, NavigateComponent : function(component, event, helper) { if(event.getParam("navigate") == "true") { $A.createComponent("c:studyDetail", { }, function(newCmp) { if (component.isValid()) { component.set("v.body", newCmp); } }); } }
buttonFunction : function(component, event) { var event = $A.get("e.c:navigateToCmp"); event.setParams({ "navigate" : "true" }); event.fire(); },
<aura:event access="global" type="APPLICATION" description="Event template" > <aura:attribute name="navigate" type="Boolean" default="false"/> </aura:event>
Main.cmp
1
<aura:component
implements=
"force:appHostable,flexipage:availableForAllPageTypes"
>
2
3
<ui:button
label=
"Navigate to C1"
press=
"{!c.Navigate}"
/
>
4
5
{!v.body}
6
7
</aura:component
>
MainController.js
01
({
02
Navigate : function(component, event, helper) {
03
$A.createComponent(
04
"c:C1"
,
05
{
06
07
},
08
function(newCmp){
09
if
(component.isValid()) {
10
var body
=
component.
get
(
"v.body"
);
11
body.push(newCmp);
12
component.set(
"v.body"
, body);
13
}
14
}
15
);
16
17
}
18
})
C1.cmp
1
<aura:component
>
2
3
Component C
1
Successfully Loaded ! ! !
4
5
</aura:component
>