Last active
August 20, 2016 23:01
-
-
Save johnpapa/9f6d8f89072077bcaff82bc03b9a31fe to your computer and use it in GitHub Desktop.
Angular 2 data binding progression
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
<div> | |
<h2>Binding</h2> | |
<h4>Interpolation</h4> | |
<pre>Hello { {firstName }}</pre> | |
<div>Hello {{firstName}}</div> | |
<hr> | |
<h4>Property Binding Without Two-Way</h4> | |
<pre><input [value]="city"></pre> | |
<input [value]="city"> | |
<p>City = {{city}}</p> | |
<hr> | |
<h4>Binding With Two-Way (Long Form)</h4> | |
<pre><input [value]="city" (input)="city = $event.target.value"></pre> | |
<input [value]="city" (input)="city = $event.target.value"> | |
<p>City = {{city}}</p> | |
<hr> | |
<h4>Two-Way Binding (ngModel directive long form)</h4> | |
<pre><input [ngModel]="firstName" (ngModel)="firstName=$event"/> </pre> | |
<input [ngModel]="firstName" (ngModel)="firstName=$event"/> {{firstName}} | |
<hr> | |
<h4>Two-Way Binding (sugar)</h4> | |
<pre><input [(ngModel)]="lastName" /> </pre> | |
<input [(ngModel)]="lastName" /> {{lastName}} | |
<hr> | |
<h4>Two-Way Binding (classic style)</h4> | |
<pre><input bindOnNgModel="city" /></pre> | |
<input bindOnNgModel="city" /> {{city}} | |
<hr> | |
<h4>Local Variables</h4> | |
<pre> | |
<input #mylocalvar/>{ {mylocalvar.value}} | |
<button (click)="addThing(mylocalvar.value)">Add Local Var</button> | |
</pre> | |
<input #mylocalvar/>{{mylocalvar.value}} | |
<button (click)="addThing(mylocalvar.value)">Add Local Var</button> | |
<div>Async Piped Data from 500ms delay = {{ dataAsync | async | json }}</div> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment