Skip to content

Instantly share code, notes, and snippets.

@Deviad
Created April 17, 2016 09:40
Show Gist options
  • Save Deviad/7c0ca9e6a3e514a99f835c0401d73f9f to your computer and use it in GitHub Desktop.
Save Deviad/7c0ca9e6a3e514a99f835c0401d73f9f to your computer and use it in GitHub Desktop.
Two way Data Binding Example
import {Component} from 'angular2/core';
import {PropertyBindingComponent} from "./property-binding.component";
@Component({
selector: 'app',
template: `
<section class="parent">
<h2>This is the parent component</h2>
<h4>Please, enter your name:</h4>
<input type="text" [(ngModel)]="name">
<br><br>
<section class="child">
<my-property-binding>
[myName]="name" [myAge]="26"
</my-property-binding>
</section>
</section>
`,
directives: [PropertyBindingComponent]
})
export class AppComponent {
name = '';
}
/// <reference path="../typings/browser.d.ts" />
import {bootstrap} from 'angular2/platform/browser';
import {AppComponent} from "./app.component";
bootstrap(AppComponent);
import {Component} from 'angular2/core';
@Component ({
selector: 'my-property-binding',
template: `
<h2>This is a child component</h2>
<p>Hey, my name is {{myName}} and I am {{myAge}} years old!</p>
`,
inputs: ['myName', 'myAge']
})
export class PropertyBindingComponent {
myName = '';
myAge = 20;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment