Go to file
Kara Erickson 8fb34bcd43 refactor(forms): deprecate ngModel usage on same field as formControl (#22633)
Support for using the `ngModel` input property and `ngModelChange`
event with reactive form directives has been deprecated in
Angular v6 and will be removed in Angular v7.

Now deprecated:
```html
<input [formControl]="control" [(ngModel)]="value">
```

```ts
this.value = 'some value';
```

This has been deprecated for a few reasons. First, developers have
found this pattern confusing. It seems like the actual `ngModel`
directive is being used, but in fact it's an input/output property
named `ngModel` on the reactive form directive that simply approximates
(some of) its behavior. Specifically, it allows getting/setting the
value and intercepting value events. However, some of `ngModel`'s other
features - like delaying updates with`ngModelOptions` or exporting the
directive - simply don't work, which has understandably caused some
confusion.

In addition, this pattern mixes template-driven and reactive forms
strategies, which we generally don't recommend because it doesn't take
advantage of the full benefits of either strategy. Setting the value in
the template violates the template-agnostic principles behind reactive
forms, whereas adding a FormControl/FormGroup layer in the class removes
the convenience of defining forms in the template.

To update your code before v7, you'll want to decide whether to stick
with reactive form directives (and get/set values using reactive forms
patterns) or switch over to template-driven directives.

After (choice 1 - use reactive forms):

```html
<input [formControl]="control">
```

```ts
this.control.setValue('some value');
```

After (choice 2 - use template-driven forms):

```html
<input [(ngModel)]="value">
```

```ts
this.value = 'some value';
```

You can also choose to silence this warning by providing a config for
`ReactiveFormsModule` at import time:

```ts
imports: [
  ReactiveFormsModule.withConfig({warnOnNgModelWithFormControl: 'never'});
]
```

Alternatively, you can choose to surface a separate warning for each
instance of this pattern with a config value of `"always"`. This may
help to track down where in the code the pattern is being used as the
code is being updated.

Note: `warnOnNgModelWithFormControl` is set up as deprecated so that it
can be removed in v7 when it is no longer needed. This will not display
properly in API docs yet because dgeni doesn't yet support deprecating
properties in object literals, but we have an open issue to resolve the
discrepancy here: https://github.com/angular/angular/issues/22640.

PR Close #22633
2018-03-07 20:47:53 -08:00
.circleci ci: speed up lint job on CircleCI (#22526) 2018-03-01 09:12:58 -08:00
.github ci: update github bot config (#22453) 2018-02-27 15:18:36 -08:00
aio docs: add HeroService to code tabs and fix headers (#22373) 2018-03-07 18:20:53 -08:00
docs docs: update RELEASE_SCHEDULE.md by pushing out v6 rc by one week 2018-03-07 10:50:55 -08:00
integration fix(bazel): fixes for ng_package on Windows (#22597) 2018-03-06 07:52:48 -08:00
modules refactor(ivy): rename `bindX()` functions to `interpolationX()` (#22229) 2018-02-15 14:20:53 -08:00
packages refactor(forms): deprecate ngModel usage on same field as formControl (#22633) 2018-03-07 20:47:53 -08:00
scripts build: add support for the "merge-assistance" label in merge-pr (#22414) 2018-02-23 12:58:30 -08:00
tools refactor(forms): deprecate ngModel usage on same field as formControl (#22633) 2018-03-07 20:47:53 -08:00
.bowerrc chore(dgeni): clean up legacy typings bundle creation 2015-10-29 21:19:59 +00:00
.clang-format feat(tooling): Add a .clang-format for automated JavaScript formatting. 2015-04-02 08:44:34 -07:00
.editorconfig chore(.editorconfig): include markdown config 2015-01-27 00:14:48 -08:00
.gitattributes chore: force lf EOL for ts files (#11143) 2016-08-29 12:41:58 -07:00
.gitignore build(common): extract i18n locale data from cldr (#18284) 2017-08-22 15:43:04 -05:00
.mailmap build: add a Git .mailmap with my new name (#19550) 2017-10-09 14:35:30 -07:00
.nvmrc build: update node version number in .nvmrc (#20832) 2017-12-12 11:56:18 -08:00
.pullapprove.yml ci: mark PRs with rejection as not green (#21922) 2018-02-05 13:01:11 -08:00
.travis.yml ci: remove bazel job from Travis (#22170) 2018-02-13 10:25:51 -08:00
BUILD.bazel test(bazel): Build and test ts-api-guardian locally (#22544) 2018-03-02 15:00:00 -08:00
CHANGELOG.md docs: add changelog for 6.0.0-beta.7 2018-03-07 14:59:33 -08:00
CODE_OF_CONDUCT.md docs: fix community tab in GitHub by copying CoC 2018-02-27 19:02:30 -08:00
CONTRIBUTING.md docs: correct grammar mistakes in CONTRIBUTING.md (#22285) 2018-02-18 13:27:23 -08:00
LICENSE docs(common): update copyright years (#21232) 2018-01-04 17:45:36 -05:00
README.md docs: remove broken issuestats.com badges (#21334) 2018-01-05 14:43:18 -05:00
WORKSPACE build: add an npm_package rule for @angular/bazel (#22628) 2018-03-07 10:56:27 -08:00
bower.json docs: branding fixes (#14132) 2017-01-27 15:03:11 -06:00
browser-providers.conf.js build: remove required BrowserStack run as it fails with “Access denied” (#19769) 2017-10-17 15:51:40 -07:00
build.sh release: packageGroup should use scoped package names (#22538) 2018-03-02 14:05:59 -08:00
gulpfile.js test(packaging): added test for source map correctness 2017-09-12 16:59:32 -04:00
karma-js.conf.js test(upgrade): run tests against multiple AngularJS versions (#22167) 2018-02-25 10:06:14 -08:00
package.json release: cut the 6.0.0-beta.7 release 2018-03-07 14:57:04 -08:00
protractor-e2e.conf.js refactor: add license header to JS files & format files (#12081) 2016-10-04 20:39:20 -07:00
protractor-examples-e2e.conf.js refactor: format and lint code 2016-12-12 11:30:25 -08:00
protractor-perf.conf.js refactor: add license header to JS files & format files (#12081) 2016-10-04 20:39:20 -07:00
shims_for_IE.js Revert "refactor: add license header to JS files & format files (#12035)" 2016-10-04 14:06:41 -07:00
test-events.js fix(platform-browser): run BLACK_LISTED_EVENTS outside of ngZone (#18993) 2017-09-05 15:33:22 -05:00
test-main.js build: add bazel test rules for remainder of packages (#21053) 2017-12-22 13:10:51 -08:00
test.sh build: remove references to `tsc-wrapped` (#19298) 2017-09-21 13:55:52 -07:00
tslint.json build: add lint rule for global flags in rollup config (#20028) 2017-10-30 23:09:16 -04:00
yarn.lock test(bazel): Build and test ts-api-guardian locally (#22544) 2018-03-02 15:00:00 -08:00
yarn.lock.readme.md build: switch from npm to yarn (#19328) 2017-09-22 13:20:52 -07:00

README.md

Build Status CircleCI BrowserStack Status Join the chat at https://gitter.im/angular/angular npm version

Sauce Test Status

Safari (7+), iOS (7+) and IE mobile (11) are tested on BrowserStack.

Angular

Angular is a development platform for building mobile and desktop web applications using Typescript/JavaScript and other languages.

Quickstart

Get started in 5 minutes.

Want to help?

Want to file a bug, contribute some code, or improve documentation? Excellent! Read up on our guidelines for contributing and then check out one of our issues in the hotlist: community-help.