ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked.

?

解決方案:

  • 異步更新(建議使用)
  • 強制進行變更檢測,但是會觸發子組件的變更檢測,再次導致父組件屬性改變

Parent.Component.ts

@Component({selector:"app-parent"
})export class ParentComponent implements OnInit,AfterViewInit {public text = "給子組件的信息";constructor(private cdr: ChangeDetectorRef){}ngOnInit(){}// 該方法缺點: 子組件多的情況下,不易控制。不建議使用
    ngAfterViewInit(){this.cdr.detectChanges();}
}

Child.Component.ts

@Component({selector:"app-child"
})export class ChildComponent implements OnInit, AfterViewInit {@Input text;constructor(private parentComponent: ParentComponent){}ngOnInit(){}ngAfterViewInit() {// 異步更新兩種方式// 第一種setTimeout( ()=>{this.parentComponent.text="update message"},2000);// 第二種Promise.resolve(null).then( ()=> {this.parentComponent.text="update message"});}
}

?

?

參考原文:https://blog.csdn.net/friend_ship/article/details/81773057

?

轉載于:https://www.cnblogs.com/wjw1014/p/11313167.html

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/391845.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/391845.shtml
英文地址,請注明出處:http://en.pswp.cn/news/391845.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

leetcode 119. 楊輝三角 II

給定一個非負索引 k,其中 k ≤ 33,返回楊輝三角的第 k 行。 在楊輝三角中,每個數是它左上方和右上方的數的和。 示例: 輸入: 3 輸出: [1,3,3,1] 解題思路 因為楊輝三角的下層由上一層決定,所以只需要保存上一層的元素&#x…

掌握大數據數據分析師嗎?_要掌握您的數據嗎? 這就是為什么您應該關心元數據的原因...

掌握大數據數據分析師嗎?Either you are a data scientist, a data engineer, or someone enthusiastic about data, understanding your data is one thing you don’t want to overlook. We usually regard data as numbers, texts, or images, but data is more than that.…

react 使用 mobx_如何使用React和MobX狀態樹構建基于狀態的路由器

react 使用 mobxby Miles Till由Miles Till 如何使用React和MobX狀態樹構建基于狀態的路由器 (How to build a state-based router using React and MobX State Tree) Introducing mobx-state-tree-routerMobx狀態樹路由器簡介 If you want to skip ahead to the finished ex…

docker在Centos上的安裝

Centos6安裝docker 系統:centos6.5 內核:3.10.107-1(已升級),docker對RHEL/Centos的最低內核支持是2.6.32-431,epel源的docker版本推薦內核為3.10版本。 內核升級可參考:https://www.jslink.org/linux/centos-kernel-u…

Lambda表達式的前世今生

Lambda 表達式 早在 C# 1.0 時,C#中就引入了委托(delegate)類型的概念。通過使用這個類型,我們可以將函數作為參數進行傳遞。在某種意義上,委托可理解為一種托管的強類型的函數指針。 通常情況下,使用委托來…

matplotlib柱狀圖、面積圖、直方圖、散點圖、極坐標圖、箱型圖

一、柱狀圖 1.通過obj.plot() 柱狀圖用bar表示,可通過obj.plot(kindbar)或者obj.plot.bar()生成;在柱狀圖中添加參數stackedTrue,會形成堆疊圖。 fig,axes plt.subplots(2,2,figsize(10,6)) s pd.Series(np.random.randint(0,10,15),index …

微信支付商業版 結算周期_了解商業周期

微信支付商業版 結算周期Economics is an inexact science, finance and investing even more so (some would call them art). But if there’s one thing in economics that you can consistently count on over the long run, it’s the tendency of things to mean revert …

leetcode 448. 找到所有數組中消失的數字

給定一個范圍在 1 ≤ a[i] ≤ n ( n 數組大小 ) 的 整型數組,數組中的元素一些出現了兩次,另一些只出現一次。 找到所有在 [1, n] 范圍之間沒有出現在數組中的數字。 您能在不使用額外空間且時間復雜度為O(n)的情況下完成這個任務嗎? 你可以假定返回…

前端初學者開發學習視頻_初學者學習前端開發的實用指南

前端初學者開發學習視頻by Nikita Rudenko通過尼基塔魯登科(Nikita Rudenko) 初學者學習前端開發的實用指南 (A practical guide to learning front end development for beginners) I started my coding journey in spring 2018, a bit less than one year ago. I earned som…

weblogic啟動失敗案例(root啟動引起的權限問題)

weblogic的一個domain啟動失敗,在日志中有如下信息提示: **************************************************** To start WebLogic Server, use a username and ** password assigned to an admin-level user. For ** server administration, us…

HTTP請求示例

HTTP請求格式當瀏覽器向Web服務器發出請求時,它向服務器傳遞了一個數據塊,也就是請求信息,HTTP請求信息由3部分組成:l 請求方法URI協議/版本l 請求頭(Request Header)l 請求正文下面是一個HTTP請求的例子:GET/sa…

Bootstrap——可拖動模態框(Model)

還是上一個小項目,o(╥﹏╥)o,要實現點擊一個div或者button或者一個東西然后可以彈出一個浮在最上面的彈框。網上找了找,發現Bootstrap的Model彈出框可以實現該功能,因此學習了一下,實現了基本彈框功能(可拖…

mfcc中的fft操作_簡化音頻數據:FFT,STFT和MFCC

mfcc中的fft操作What we should know about sound. Sound is produced when there’s an object that vibrates and those vibrations determine the oscillation of air molecules which creates an alternation of air pressure and this high pressure alternated with low …

leetcode 765. 情侶牽手(并查集)

N 對情侶坐在連續排列的 2N 個座位上,想要牽到對方的手。 計算最少交換座位的次數,以便每對情侶可以并肩坐在一起。 一次交換可選擇任意兩人,讓他們站起來交換座位。 人和座位用 0 到 2N-1 的整數表示,情侶們按順序編號&#xff…

ariel字體_播客第58集:軟件開發人員和freeCodeCamp超級巨星Ariel Leslie

ariel字體On this weeks episode of the freeCodeCamp.org podcast, Abbey interviews Ariel Leslie, a software developer and avid contributor to the freeCodeCamp community.在本周的freeCodeCamp.org播客節目中,Abbey采訪了Ariel Leslie,他是free…

PHP繪制3D圖形

PEAR提供了Image_3D Package來創建3D圖像。圖像或光線在3D空間中按照X、Y 、Z 坐標定位。生成的圖像將呈現在2D空間中,可以存儲為 PNG、SVG 格式,或輸出到Shell。通過Image_3D可以很方便生成一些簡單的3D對象,例如立方體、錐體、球體、文本和…

清除日志的sql

SET NOCOUNT ONDECLARE LogicalFileName sysname,MaxMinutes INT,NewSize INTUSE cms -- 要操作的數據庫名SELECT LogicalFileName cms_log, -- 日志文件名MaxMinutes 10, -- Limit on time allowed to wrap log.NewSize 100 -- 你想設定的日志文件的大小(M)-- Setup / init…

r語言怎么以第二列繪制線圖_用衛星圖像繪制世界海岸線圖-第二部分

r語言怎么以第二列繪制線圖Part I of this blog series is here.本博客系列的第一部分 在這里 。 At the UKHO we are interested in the oceans, the seabed and the coastline — not to mention everything in and on them! In our previous blog, we (the UKHO Data Scien…

javascript創建類_如何在10分鐘內使用JavaScript創建費用管理器

javascript創建類by Per Harald Borgen通過Per Harald Borgen 如何在10分鐘內使用JavaScript創建費用管理器 (How to create an expense organizer with JavaScript in 10 minutes) 讓我們使用ES6和Dropbox API來防止收據變得混亂。 (Let’s use ES6 and the Dropbox API to k…

豆瓣API

Api V2 索引 圖書Api V2 電影Api V2 音樂Api V2 同城Api V2 廣播Api V2 用戶Api V2 日記Api V2 相冊Api V2 線上活動Api V2 論壇Api V2 回復Api V2 我去Api V2 https://developers.douban.com/wiki/?titleapi_v2 搜索圖書 GET https://api.douban.com/v2/book/search參數意義…