当前位置:网站首页>ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
2022-06-23 13:25:00 【51CTO】
ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.
Solution :
- Asynchronous update ( It is recommended to use )
- Force change detection , But it will trigger the change detection of sub components , This causes the parent component properties to change again
Parent.Component.ts
@Component({
selector:"app-parent"
})
export class ParentComponent implements OnInit,AfterViewInit {
public text = " Information for subcomponents ";
constructor(private cdr: ChangeDetectorRef){}
ngOnInit(){}
// The disadvantages of this method : When there are many sub components , Not easy to control . Not recommended
ngAfterViewInit(){
this.cdr.detectChanges();
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
Child.Component.ts
@Component({
selector:"app-child"
})
export class ChildComponent implements OnInit, AfterViewInit {
@Input text;
constructor(private parentComponent: ParentComponent){}
ngOnInit(){}
ngAfterViewInit() {
// Two methods of asynchronous update
// The first one is
setTimeout( ()=>{
this.parentComponent.text="update message"
},2000);
// The second kind
Promise.resolve(null).then( ()=> {this.parentComponent.text="update message"});
}
}
- 1.
- 2.
- 3.
- 4.
- 5.
- 6.
- 7.
- 8.
- 9.
- 10.
- 11.
- 12.
- 13.
- 14.
- 15.
- 16.
- 17.
- 18.
- 19.
- 20.
- 21.
- 22.
- 23.
- 24.
【 Copyright notice 】 The copyright of this blog belongs to the author , For any form of reprint, please contact the author for authorization and indicate the source !
【 Important note 】 This article is my study record , Arguments and opinions only represent individuals and do not represent the truth of technology at that time , The goal is to learn from yourself and be fortunate enough to be an experience that can be shared with others , Therefore, mistakes will be accepted and corrected with an open mind , But it doesn't mean that the blog is correct at the moment !
【Gitee Address 】 Qin Haocheng : https://gitee.com/wjw1014
边栏推荐
- < Sicily> 1000. number reversal
- 2 万字 + 30 张图 |MySQL 日志:undo log、redo log、binlog 有什么用?
- Can cold plate, submerged and spray liquid cooling lead the development of high-performance computing?
- Capacity limited facility location problem
- .Net怎么使用日志框架NLog
- 你管这破玩意儿叫 MQ?
- Hanyuan high tech USB2.0 optical transceiver USB2.0 optical fiber extender USB2.0 optical fiber transmitter USB2.0 interface to optical fiber
- Network foundation and framework
- Broadcast level E1 to aes-ebu audio codec E1 to stereo audio XLR codec
- How did Tencent's technology bulls complete the overall cloud launch?
猜你喜欢

Part C - value types and reference types

618's money saving technology strategy is coming - experience the scene and get a 10 yuan cat super card!

Go寫文件的權限 WriteFile(filename, data, 0644)?

Hanyuan hi tech 1-way uncompressed 4k-dvi optical transceiver 4K HD uncompressed DVI to optical fiber 4k-dvi HD video optical transceiver

618的省钱技术攻略 来啦 -体验场景 领取10元猫超卡!
[email protected] Hdmi2.0 optical transceiver HDMI HD video optical transceiver"/>4k-hdmi optical transceiver 1 channel [email protected] Hdmi2.0 optical transceiver HDMI HD video optical transceiver

AssetBundle resource management
![[deeply understand tcapulusdb technology] transaction execution of document acceptance](/img/d9/f6735906a130834c4b3e28de2b2617.png)
[deeply understand tcapulusdb technology] transaction execution of document acceptance

Qunhui 10 Gigabit network configuration and test

#yyds干货盘点# 解决剑指offer: 判断是不是平衡二叉树
随机推荐
Gradle Build Cache引发的Task缓存编译问题怎么解决
Synergetic process
Go write permissions to file writefile (FileName, data, 0644)?
You call this shit MQ?
Cloud native essay deep understanding of ingress
In flinksql, the Kafka flow table and MySQL latitude flow table are left joined, and the association is made according to I'd. false
RestCloud ETL解决shell脚本参数化
Online text entity extraction capability helps applications analyze massive text data
OS的常见用法(图片示例)
Go写文件的权限 WriteFile(filename, data, 0644)?
TUIKit 音视频低代码解决方案导航页
LM05丨曾经的VIX(二代产品)
R language dplyr package mutate_ The all function multiplies all numeric columns (variables) in the dataframe by a fixed value to generate a new data column, and specifies a user-defined suffix name f
618's money saving technology strategy is coming - experience the scene and get a 10 yuan cat super card!
逆向调试入门-了解PE结构文件
< Sicily> 1000. number reversal
Quickly understand the commonly used asymmetric encryption algorithm, and no longer have to worry about the interviewer's thorough inquiry
Broadcast level E1 to aes-ebu audio codec E1 to stereo audio XLR codec
Gary Marcus wrote: three perspectives from linguists that AI researchers need to know
State machine framework