Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Save Automatically?

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <main-component>
	Loading app...
	<script type=template selector=main-component>
		<h1>hi there!</h1>
		<button (click)="addName()">add</button>
		<h3>Children:</h3>
		<input #input *ngFor="#name of names" [value]="name">
	</script>
	<script type=template selector=child-component>
		<li>child: {{name}}
	</script>
</main-component>

              
            
!

CSS

              
                [selector] { display: none; }
              
            
!

JS

              
                const {bind, Component, Injectable, Inject, Input, ViewChildren, AfterViewInit, ElementRef} = ng.core;
const {bootstrap} = ng.platform.browser;

@Component(addTemplateFromDOM({
	selector: 'child-component'
}))
class ChildComponent {
	@Input() name: string;
}

@Component(addTemplateFromDOM({
	selector: 'main-component',
	directives: [ChildComponent]
}))
class MainComponent implements AfterViewInit {
	names: string[];
	@ViewChildren('input') childChildren: QueryList<ElementRef>;
	
	constructor() {
		this.names = ['Wednesday', 'Pugsley', 'Pubert'];
	}
	
	ngAfterViewInit() {
		this.childChildren.changes.subscribe(children => {
			children.last.nativeElement.focus();
		});
	}
	
	addName() {
		this.names.push('Child-'+Math.floor(Math.random()*100));
	}
}

bootstrap(MainComponent, []);


// ******** HELPER FUNCTIONS **********
// really taking advantage of hoisting here, to make the actual non-template
// code more visible on codepen

function addTemplateFromDOM(selector: string | {template?: string, selector: string}) : string | {template: string, selector: string} {
	if (typeof selector === 'string') {
		let element = document.querySelector(`[selector=${selector}]`);
		if (!element) {
			console.error(`Cannot load template for component "${selector}"`);
			return '';
		}
		return element.innerHTML;
	} else if (typeof selector === 'object') {
		selector.template = addTemplateFromDOM(selector.selector);
		return selector;
	}
}

              
            
!
999px

Console