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

790 B

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

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

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.
  }
}