docs(API): 翻译 ng_model

This commit is contained in:
Zhicheng Wang 2018-08-30 13:43:39 +08:00
parent 9f34b155c4
commit fcfe9c581d
1 changed files with 57 additions and 0 deletions

View File

@ -29,6 +29,7 @@ export const formControlBinding: any = {
/**
* `ngModel` forces an additional change detection run when its inputs change:
* E.g.:
* <p>`ngModel` </p>
* ```
* <div>{{myModel.valid}}</div>
* <input [(ngModel)]="myValue" #myModel="ngModel">
@ -39,9 +40,22 @@ export const formControlBinding: any = {
* dirty checked before. As this is a very common case for `ngModel`, we added this second change
* detection run.
*
* `ngModel` 使
* `input` 使
* `ngModel`
*
* Notes:
*
*
*
* - this is just one extra run no matter how many `ngModel` have been changed.
*
* `ngModel`
*
* - this is a general problem when using `exportAs` for directives!
*
* 使 `exportAs`
*
*/
const resolvedPromise = Promise.resolve(null);
@ -50,21 +64,30 @@ const resolvedPromise = Promise.resolve(null);
*
* Creates a `FormControl` instance from a domain model and binds it
* to a form control element.
* <p> `FormControl` </p>
*
* The `FormControl` instance will track the value, user interaction, and
* validation status of the control and keep the view synced with the model. If used
* within a parent form, the directive will also register itself with the form as a child
* control.
*
* `FormControl`
*
*
* This directive can be used by itself or as part of a larger form. All you need is the
* `ngModel` selector to activate it.
*
* 使 `ngModel`
*
* It accepts a domain model as an optional `Input`. If you have a one-way binding
* to `ngModel` with `[]` syntax, changing the value of the domain model in the component
* class will set the value in the view. If you have a two-way binding with `[()]` syntax
* (also known as 'banana-box syntax'), the value in the UI will always be synced back to
* the domain model in your class as well.
*
* `Input`使 `[]` `ngModel`
* 使 `[()]` `ngModel`
*
* If you wish to inspect the properties of the associated `FormControl` (like
* validity state), you can also export the directive into a local template variable using
* `ngModel` as the key (ex: `#myVar="ngModel"`). You can then access the control using the
@ -72,33 +95,58 @@ const resolvedPromise = Promise.resolve(null);
* will fall through to the control anyway, so you can access them directly. You can see a
* full list of properties directly available in `AbstractControlDirective`.
*
* `FormControl` 使 `ngModel` `#myVar="ngModel"`
* 使 `control` 访 `valid` `dirty`访
* `AbstractControlDirective`
*
* The following is an example of a simple standalone control using `ngModel`:
*
* 使 `ngModel`
*
* {@example forms/ts/simpleNgModel/simple_ng_model_example.ts region='Component'}
*
* When using the `ngModel` within `<form>` tags, you'll also need to supply a `name` attribute
* so that the control can be registered with the parent form under that name.
*
* `<form>` 使 `ngModel` `name` 便使
*
* It's worth noting that in the context of a parent form, you often can skip one-way or
* two-way binding because the parent form will sync the value for you. You can access
* its properties by exporting it into a local template variable using `ngForm` (ex:
* `#f="ngForm"`). Then you can pass it where it needs to go on submit.
*
*
* 使 `ngForm` `#f="ngForm"`访
*
*
* If you do need to populate initial values into your form, using a one-way binding for
* `ngModel` tends to be sufficient as long as you use the exported form's value rather
* than the domain model's value on submit.
*
* `ngModel` 使使使
*
* Take a look at an example of using `ngModel` within a form:
*
* 使 `ngModel`
*
* {@example forms/ts/simpleForm/simple_form_example.ts region='Component'}
*
* To see `ngModel` examples with different form control types, see:
*
* `ngModel`
*
* * Radio buttons: `RadioControlValueAccessor`
*
* `RadioControlValueAccessor`
*
* * Selects: `SelectControlValueAccessor`
*
* `SelectControlValueAccessor`
*
* **npm package**: `@angular/forms`
*
* **npm **: `@angular/forms`
*
* **NgModule**: `FormsModule`
*
*
@ -123,12 +171,16 @@ export class NgModel extends NgControl implements OnChanges,
/**
* Options object for this `ngModel` instance. You can configure the following properties:
* <p> `ngModel` </p>
*
* **name**: An alternative to setting the name attribute on the form control element.
* Sometimes, especially with custom form components, the name attribute might be used
* as an `@Input` property for a different purpose. In cases like these, you can configure
* the `ngModel` name through this option.
*
* **name**name `@Input`
* `ngModel`
*
* ```html
* <form>
* <my-person-control name="Nancy" ngModel [ngModelOptions]="{name: 'user'}">
@ -142,6 +194,9 @@ export class NgModel extends NgControl implements OnChanges,
* can be handy if you have form meta-controls, a.k.a. form elements nested in
* the `<form>` tag that control the display of the form, but don't contain form data.
*
* **standalone** `false` `true` `ngModel`
* 使便 `<form>`
*
* ```html
* <form>
* <input name="login" ngModel placeholder="Login">
@ -153,6 +208,8 @@ export class NgModel extends NgControl implements OnChanges,
* **updateOn**: Defaults to `'change'`. Defines the event upon which the form control
* value and validity will update. Also accepts `'blur'` and `'submit'`.
*
* **updateOn** `'change'``'blur'` `'submit'`
*
* ```html
* <input [(ngModel)]="firstName" [ngModelOptions]="{updateOn: 'blur'}">
* ```