Components topic code example updates (#12893)

pull/12984/head
Luke Latham 2019-06-22 23:06:35 -05:00 committed by GitHub
parent 4ce108f514
commit 692fb252b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 8 additions and 8 deletions

View File

@ -21,7 +21,7 @@
_italicsCheck field.
*@
<input type="checkbox" id="italicsCheck"
@bind="@_italicsCheck" />
@bind="_italicsCheck" />
<label class="form-check-label"
for="italicsCheck">Use italics</label>
</div>

View File

@ -8,7 +8,7 @@
<h4>Greetings from the first tab!</h4>
<label>
<input type="checkbox" @bind="@showThirdTab" />
<input type="checkbox" @bind="showThirdTab" />
Toggle third tab
</label>
</Tab>
@ -49,7 +49,7 @@ namespace BlazorSample.UIInterfaces
&lt;h4&gt;Greetings from the first tab!&lt;/h4&gt;
&lt;label&gt;
&lt;input type="checkbox" @@bind="@@showThirdTab" /&gt;
&lt;input type="checkbox" @@bind="showThirdTab" /&gt;
Toggle third tab
&lt;/label&gt;
&lt;/Tab&gt;

View File

@ -40,7 +40,7 @@
@@*
A check box sets the font style and is bound to the _italicsCheck field.
*@@
&lt;input type="checkbox" id="italicsCheck" @@bind="@@_italicsCheck" /&gt;
&lt;input type="checkbox" id="italicsCheck" @@bind="_italicsCheck" /&gt;
&lt;label class="form-check-label" for="italicsCheck"&gt;Use italics&lt;/label&gt;
&lt;/div&gt;

View File

@ -5,7 +5,7 @@ description: Learn how to create and use Razor components, including how to bind
monikerRange: '>= aspnetcore-3.0'
ms.author: riande
ms.custom: mvc
ms.date: 06/12/2019
ms.date: 06/16/2019
uid: blazor/components
---
# Create and use Razor components
@ -139,13 +139,13 @@ Using `@bind` with a `CurrentValue` property (`<input @bind="CurrentValue" />`)
When the component is rendered, the `value` of the input element comes from the `CurrentValue` property. When the user types in the text box, the `onchange` event is fired and the `CurrentValue` property is set to the changed value. In reality, the code generation is a little more complex because `@bind` handles a few cases where type conversions are performed. In principle, `@bind` associates the current value of an expression with a `value` attribute and handles changes using the registered handler.
In addition to `onchange`, the property can be bound using other events like `oninput` by adding a `@bind` attribute with an `event` parameter:
In addition to handling `onchange` events with `@bind` syntax, a property or field can be bound using other events by specifying an `@bind-value` attribute with an `event` parameter. The following example binds the `CurrentValue` property for the `oninput` event:
```cshtml
<input type="text" @bind-value="@CurrentValue" @bind-value:event="oninput" />
<input @bind-value="CurrentValue" @bind-value:event="oninput" />
```
Unlike `onchange`, `oninput` fires for every character that is input into the text box.
Unlike `onchange`, which fires when the element loses focus, `oninput` fires when the value of the text box changes.
**Format strings**