angular-cn/packages/core/schematics/migrations/abstract-control-parent/README.md

35 lines
790 B
Markdown
Raw Normal View History

## `AbstractControl.parent` migration
As of Angular v11, the type of `AbstractControl.parent` can be null. This migration automatically
identifies usages and adds non-null assertions.
#### Before
```ts
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component()
export class MyComponent {
private _control = new FormControl();
getParentValue() {
return this._control.parent.value; // <- Compilation error in v11.
}
}
```
#### After
```ts
import { Component } from '@angular/core';
import { FormControl } from '@angular/forms';
@Component()
export class MyComponent {
private _control = new FormControl();
getParentValue() {
return this._control.parent!.value; // <- Non-null assertion added during the migration.
}
}
```