Created
February 26, 2017 02:55
-
-
Save Sunil02kumar/0bf29d8f56f9ded7986276f11a4f7b78 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <aura:component > | |
| <lightning:button label="Create Button" onclick="{!c.createButtonDynamically}" variant="brand"/> | |
| <lightning:button label="Destroy All buttons" onclick="{!c.removeButtonDynamically}" variant="destructive"/> | |
| <br/> | |
| <div style="margin:auto; height:600px; width:400px; border:2px ridge red;" aura:id="newtag"> | |
| {!v.body} | |
| </div> | |
| </aura:component> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ({ | |
| createButtonDynamically : function(component, event, helper) { | |
| var db=component.find("newtag"); | |
| $A.createComponent( | |
| "ui:button", | |
| { | |
| "label":"New Button"+db.get("v.body").length, | |
| "press": component.getReference("c.showPressedButtonLabel") | |
| }, | |
| function(bn) | |
| { | |
| var bdy=db.get("v.body"); | |
| bdy.push(bn); | |
| db.set("v.body",bdy); | |
| } | |
| ); | |
| }, | |
| removeButtonDynamically : function(component, event, helper){ | |
| component.find("newtag").set("v.body",[]); | |
| }, | |
| showPressedButtonLabel : function(component, event, helper){ | |
| alert('You pressed:'+event.getSource().get("v.label")); | |
| } | |
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <aura:application extends="force:slds" > | |
| <c:CreateAndDestroyComp /> | |
| </aura:application> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment