docs(forms): update docs for FormBuilder (#11548)
This commit is contained in:
@ -0,0 +1,36 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {verifyNoBrowserErrors} from '../../../../_common/e2e_util';
|
||||
|
||||
describe('formBuilder example', () => {
|
||||
afterEach(verifyNoBrowserErrors);
|
||||
let inputs: ElementFinder;
|
||||
let paragraphs: ElementFinder;
|
||||
|
||||
beforeEach(() => {
|
||||
browser.get('/forms/ts/formBuilder/index.html');
|
||||
inputs = element.all(by.css('input'));
|
||||
paragraphs = element.all(by.css('p'));
|
||||
});
|
||||
|
||||
it('should populate the UI with initial values', () => {
|
||||
expect(inputs.get(0).getAttribute('value')).toEqual('Nancy');
|
||||
expect(inputs.get(1).getAttribute('value')).toEqual('Drew');
|
||||
});
|
||||
|
||||
it('should update the validation status', () => {
|
||||
expect(paragraphs.get(1).getText()).toEqual('Validation status: VALID');
|
||||
|
||||
inputs.get(0).click();
|
||||
inputs.get(0).clear();
|
||||
inputs.get(0).sendKeys('a');
|
||||
expect(paragraphs.get(1).getText()).toEqual('Validation status: INVALID');
|
||||
});
|
||||
|
||||
});
|
@ -0,0 +1,42 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
// #docregion Component
|
||||
import {Component, Inject} from '@angular/core';
|
||||
import {FormBuilder, FormGroup, Validators} from '@angular/forms';
|
||||
|
||||
@Component({
|
||||
selector: 'example-app',
|
||||
template: `
|
||||
<form [formGroup]="form">
|
||||
<div formGroupName="name">
|
||||
<input formControlName="first" placeholder="First">
|
||||
<input formControlName="last" placeholder="Last">
|
||||
</div>
|
||||
<input formControlName="email" placeholder="Email">
|
||||
<button>Submit</button>
|
||||
</form>
|
||||
|
||||
<p>Value: {{ form.value | json }}</p>
|
||||
<p>Validation status: {{ form.status }}</p>
|
||||
`
|
||||
})
|
||||
export class FormBuilderComp {
|
||||
form: FormGroup;
|
||||
|
||||
constructor(@Inject(FormBuilder) fb: FormBuilder) {
|
||||
this.form = fb.group({
|
||||
name: fb.group({
|
||||
first: ['Nancy', Validators.minLength(2)],
|
||||
last: 'Drew',
|
||||
}),
|
||||
email: '',
|
||||
});
|
||||
}
|
||||
}
|
||||
// #enddocregion
|
20
modules/@angular/examples/forms/ts/formBuilder/module.ts
Normal file
20
modules/@angular/examples/forms/ts/formBuilder/module.ts
Normal file
@ -0,0 +1,20 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {NgModule} from '@angular/core';
|
||||
import {ReactiveFormsModule} from '@angular/forms';
|
||||
import {BrowserModule} from '@angular/platform-browser';
|
||||
import {FormBuilderComp} from './form_builder_example';
|
||||
|
||||
@NgModule({
|
||||
imports: [BrowserModule, ReactiveFormsModule],
|
||||
declarations: [FormBuilderComp],
|
||||
bootstrap: [FormBuilderComp]
|
||||
})
|
||||
export class AppModule {
|
||||
}
|
Reference in New Issue
Block a user