angular 子自定义元素的OnInit钩子在父元素之前被调用,

m528fe3b  于 4个月前  发布在  Angular
关注(0)|答案(1)|浏览(41)

🐞 bug report

Affected Package

The issue is caused by package @angular/elements

Is this a regression?

Dunno

Description

Wrong OnInit hooks call order when custom elements (parent + child) are added with some delay after (regular) angular component inited.

🔬 Minimal Reproduction

https://stackblitz.com/edit/angular-elements-init-order?file=app%2Fapp.component.html

  1. on toggle
> child OnInit
> parent OnInit
  1. same wrong order on replacing *ngIf="visible" with *ngIf="true"
  2. same wrong order on uncommenting window.setTimeout with innerHTML usage in AppComponent's OnInit hook
  3. correct order on removing <ng-container *ngIf="visible">
> parent OnInit
> child OnInit

🌍 Your Environment

Angular Version:

7.1.4

Anything else relevant?

No such issue with native custom elements and setTimeout + innerHTML usage
https://stackblitz.com/edit/custom-elements-init-order?file=index.ts

> parent connected
> child connected

Real word use-case: adding unknown markup with custom elements from api response.

jgzswidk

jgzswidk1#

这仍然是v9的一个问题:Updated StackBlitz
奇怪的是,只有<ng-container *ngIf="...">出现这种情况(我们需要ng-containerngIf)。我还会添加comp: core标签,因为我不确定这是否只能在@angular/elements中解决。

相关问题