gpt4 book ai didi

angular - ngOnChanges 如何处理 simpleChanges 对象

转载 作者:行者123 更新时间:2023-12-04 13:22:19 27 4
gpt4 key购买 nike

我是 Angular 5 的新手,我正在从它提供的官方网站学习组件交互

ngOnChanges(changes: {[propKey: string]: SimpleChange}) {}

并且在生命周期钩子(Hook)中

ngOnChanges(changes: SimpleChanges) {}

我知道 SimpleChanges 是 ngOnChanges 作为参数获取的对象,我们可以使用它访问以前和当前的值。但我不明白以下是如何工作的:

ngOnChanges(changes: {[propKey: string]: SimpleChange}) {}

我在任何地方都找不到任何好的解释

最佳答案

{[propKey: string]: SimpleChange}

表示:一个具有字符串类型键的对象,每个键都关联到一个 SimpleChange 类型的值。

如果您的组件有 3 个输入 a、b 和 c,并且输入 a 和 c 发生变化,那么 Angular 将使用如下参数调用 ngOnChanges():

{
a: {
previousValue: ...,
currentValue: ...,
firstChange: false
}
c: {
previousValue: ...,
currentValue: ...,
firstChange: false
}
}

关于angular - ngOnChanges 如何处理 simpleChanges 对象,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49217752/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com