angular-docs-cn/packages/core/schematics/migrations/abstract-control-parent
Kristiyan Kostadinov 190fa07b9a feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092)
Adds a migration that casts the value of `ActivatedRouteSnapshot.fragment` to be non-nullable.

Also moves some code from the `AbstractControl.parent` migration so that it can be reused.

Relates to #37336.

PR Close #41092
2021-03-23 11:18:00 -07:00
..
BUILD.bazel feat(forms): add migration for AbstractControl.parent accesses (#39009) 2020-10-06 13:55:25 -07:00
README.md feat(forms): add migration for AbstractControl.parent accesses (#39009) 2020-10-06 13:55:25 -07:00
index.ts fix(core): migration error if program contains files outside of the project (#39790) 2020-11-20 12:51:19 -08:00
util.ts feat(router): add migration for ActivatedRouteSnapshot.fragment (#41092) 2021-03-23 11:18:00 -07:00

README.md

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