Angular4_控制台错误

来源:互联网 发布:windows复制快捷键 编辑:程序博客网 时间:2024/06/05 23:40

Expression has changed after it was checked. Previous value: 'true'. Current value: 'false'.


在Component中连续多次修改一个属性值,F12页面有报这个错,找到几个解释。

Angular utilizes zones to know when an event is fully processed by patching some async APIs like (addEventHandler, setTimeout, ...) and then runs change detection after each event.

In dev mode Angular does an additional change detection run, just after the first one. Because there was no event in between, no change should have happened.

If the model still changed, Angular considers this to be a possible bug.

That's exactly it. In development mode the change detection runs a second time and compares the current value with the first run.

If the value differs, then it "thinks" that the change was caused by itself. That's why it throws. However this doesn't happen in production mode with enableProdMode().

解决方案:

import { Component, enableProdMode } from  '@angular/core';enableProdMode();


http://www.jianshu.com/p/a5402332315d
來源:简书



这段代码需要写在,别忘了引用 enableProdMode


原创粉丝点击