fix(upgrade): initialize all inputs in time for ngOnChanges()
Previously, non-bracketed inputs (e.g. `xyz="foo"`) on downgraded components were initialized using `attrs.$observe()` (which uses `$evalAsync()` under the hood), while bracketed inputs (e.g. `[xyz]="'foo'"`) were initialized using `$watch()`. If the downgraded component was created during a `$digest` (e.g. by an `ng-if` watcher), the non-bracketed inputs were not initialized in time for the initial call to `ngOnChanges()` and `ngOnInit()`. This commit fixes it by using `$watch()` to initialize all inputs. `$observe()` is still used for subsequent updates on non-bracketed inputs, because it is more performant. Fixes #16212
This commit is contained in:

committed by
Matias Niemelä

parent
77b8a76f2e
commit
b3e63c09ab
@ -10,7 +10,7 @@ import {Directive, DoCheck, ElementRef, EventEmitter, Inject, OnChanges, OnInit,
|
||||
|
||||
import * as angular from '../common/angular1';
|
||||
import {$COMPILE, $CONTROLLER, $HTTP_BACKEND, $SCOPE, $TEMPLATE_CACHE} from '../common/constants';
|
||||
import {controllerKey} from '../common/util';
|
||||
import {controllerKey, strictEquals} from '../common/util';
|
||||
|
||||
|
||||
interface IBindingDestination {
|
||||
@ -309,8 +309,7 @@ class UpgradeNg1ComponentAdapter implements OnInit, OnChanges, DoCheck {
|
||||
checkProperties.forEach((propName, i) => {
|
||||
const value = destinationObj ![propName];
|
||||
const last = lastValues[i];
|
||||
if (value !== last &&
|
||||
(value === value || last === last)) { // ignore NaN values (NaN !== NaN)
|
||||
if (!strictEquals(last, value)) {
|
||||
const eventEmitter: EventEmitter<any> = (this as any)[propOuts[i]];
|
||||
eventEmitter.emit(lastValues[i] = value);
|
||||
}
|
||||
|
Reference in New Issue
Block a user