Created
April 17, 2016 09:40
-
-
Save Deviad/7c0ca9e6a3e514a99f835c0401d73f9f to your computer and use it in GitHub Desktop.
Two way Data Binding Example
This file contains 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
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 = ''; | |
} |
This file contains 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
/// <reference path="../typings/browser.d.ts" /> | |
import {bootstrap} from 'angular2/platform/browser'; | |
import {AppComponent} from "./app.component"; | |
bootstrap(AppComponent); |
This file contains 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
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