- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
是否可以通知父组件加载子组件,尤其是当涉及到 ng-container
时?和 ng-template
.
如 Yes! I see that you've grown strong, my child!
假设我们有这样一个组件:
@Component({
selector: 'my-app',
template: `
<ng-container *ngIf="!showElse; else elseBlock">
<h1>Hi!</h1>
</ng-container>
<ng-template #elseBlock>
<hello name="{{ name }}"></hello>
</ng-template>
<button (click)="showElse = !showElse">Show else</button>
`,
styles: ['']
})
export class AppComponent {
name = 'Angular';
showElse = false;
@ViewChild('hello') hello: HelloComponent;
}
有没有办法AppComponent
知道是否HelloComponent
已满载还是我需要内部的自定义解决方案 HelloComponent
?
我目前正面临一个不太理想的解决方案(我不喜欢基于 setTimeout()
的东西)。
以下是我的想法:
- 添加 EventEmitter
到我的HelloComponent
;
- 使用 HelloComponent
的生命周期中发出一个事件,比方说,ngAfterContentChecked
- 在我的 AppComponent
中拦截此事件然后去做。
你对这个问题有什么看法?
到目前为止,我已经尝试了您的建议( Hook AfterViewInit
,利用 @ViewChildren
...)但没有成功。
可以肯定的是,我在没有 <ng-container>...<ng-template>
的情况下再次尝试东西,只是隐藏我的 HelloComponent
使用 [hidden]
指令...
通过在 HelloComponent
期间发出事件的 AfterContentChecked
并在 AppComponent
中 Hook 此事件,它就像一个魅力。 (参见 on stackblitz)
这个解决方案比我以前的 setTimeout
更优雅基于一个
现在,我想使用 <ng-container>...<ng-template>
的原因机械师是因为我的实际组件只是比示例重 一点点 HelloComponent
.
如果有人对继续使用容器模板机制有更好的想法,我会洗耳恭听。
最佳答案
如您所建议的,在生命周期 Hook AfterContentChecked() 中使用 EventEmitter 向您的父组件发出事件。它很简单,并且正确使用了 Angular 的生命周期 API。 https://angular.io/guide/lifecycle-hooks#lifecycle-sequence
关于Angular - 生命周期 : Child component to be fully loaded,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56342917/
已关闭。这个问题是 off-topic 。目前不接受答案。 想要改进这个问题吗? Update the question所以它是on-topic用于堆栈溢出。 已关闭10 年前。 Improve th
我正在尝试将 JSON 发送到我的服务器并作为结果检索 JSON。例如发送用户名和密码并取回 token 和其他内容。 这就是我正在为发送的 HTTP 请求所做的。我现在如何检索同一请求中的内容?
我有以下 xts 矩阵: > options(digits.secs = 6) > set.seed(1234) > xts(1:10, as.POSIXlt(1366039619, tz="EST"
我目前正在开发一个应用程序,当用户到达某个位置时,它会提醒用户。我希望这个应用程序也在后台运行并搜索解决方案。 在 AppStore 中,我发现了一款名为“Sleep Cycle”的应用程序,它可
我想创建一个基于 farbtastic color picker 的颜色选择器。我想要实现的是添加我想要链接到色轮的 RGB slider 。这是我到目前为止所拥有的。 app.controller(
RFC 5545 允许 RDATE 属性具有 PERIOD 数据类型。该数据类型的语义是什么?据我所知,这是未指定的。它会改变事件的持续时间吗?如果时区更改且没有持续时间怎么办? 最佳答案 尽管我
在 CodinGame学习平台,C# 教程中用作示例的问题之一是: The aim of this exercise is to check the presence of a number in a
我听说网上有一本英特尔书,它描述了特定汇编指令所需的 CPU 周期,但我找不到(经过努力)。谁能告诉我如何找到CPU周期? 这是一个例子,在下面的代码中,mov/lock 是 1 个 CPU 周期,x
据我所知,Java GC有次要GC(低成本)和主要GC周期(高成本)。如果对象在本地范围内,则会在 Minor GC 中清理它。如果对象的引用存储在代码中的其他位置,则它会在主 GC 中被清除。 例如
到目前为止,我有一个很好的自旋锁,可以用作 intendend: std::atomic_flag barrier = ATOMIC_FLAG_INIT; inline void lo
晚上好,我将 cycle2 与 prev 和 next 函数一起使用,但我无法将 prev 和 next 函数置于图像下方的中心。我环顾四周,我知道这会很愚蠢,但我就是看不到它。非常令人沮丧。谢谢加里
出于教育目的,我想知道在优化(在不同级别)和编译之后执行函数需要多少 CPU 周期。有没有办法分析代码或可执行文件以获得可重现的答案?我在 64 位 Windows 7 Pro 上使用 Eclipse
我想彻底测量和调整我的 C/C++ 代码,以便在 x86_64 系统上更好地使用缓存。我知道如何使用计数器(我的 Windows 机器上的 QueryPerformanceCounter)来测量时间,
我尝试将一些数据分组到每四周一次的存储桶中,并使用 pd.Grouper(key='created_at', freq='4W')。我希望这些组是这样的,如果我有从 2019-08-26 到 2019
我正在做一个关于随机数的大型学校项目,但我找不到 Math.random() 的句点。我安装了 7.0.800.15 版本,并且正在使用 Windows 10 计算机。我试过用一个简单的程序来确定周期
我正在努力解决我们生产环境中垃圾收集利用率高的问题,我想知道设置一个大的堆大小来保证老年代永远不会被填满是否会阻止触发主要的 GC 周期。 为了实现这一点,我想有一个特定的阈值标记会触发主要的 GC
我想测量在 Python 3 中执行加法运算所需的时钟周期数。 我写了一个程序来计算加法运算的平均值: from timeit import timeit def test(n): for i
我正在寻找一种方法来测量线程上的函数调用所花费的 cpu 周期。 示例伪代码: void HostFunction() { var startTick = CurrentThread.Cur
就 CPU 周期而言,malloc() 的成本是多少?(Vista/OS,最新版本的 gcc,最高优化级别,...) 基本上,我正在实现一个复杂的 DAG 结构(类似于链表)由一些 16B(不太常见)
C/C++ 中的类型转换会导致额外的 CPU 周期吗? 我的理解是,至少在某些情况下应该消耗额外的 CPU 周期。就像从浮点类型转换为整数一样,CPU 需要将浮点结构转换为整数。 float a=2.
我是一名优秀的程序员,十分优秀!