[英]Why does changing a parents data on NgOninit not cause ExpressionChangedAfterItHasBeenCheckedError?
Under this example 在这个例子下
parentComponent {
text = 'dsfsdf';
}
childComponent implements Oninit {
@Input() text;
ngOnInit() {
this.text = 'something else';
}
}
why does this not cause ExpressionChangedAfterItHasBeenCheckedError please? 为什么这不会引起ExpressionChangedAfterItHasBeenCheckedError? And what is a simple way of getting this error to occur?
发生此错误的简单方法是什么?
This won't trigger an ExpressionChangedAfterItHasBeenCheckedError
because changing the value of an @Input
parameter does not trigger any event to the parent and so it just doesn't re-render at all. 这不会触发
ExpressionChangedAfterItHasBeenCheckedError
因为更改@Input
参数的值不会触发任何事件给父对象,因此它根本不会重新呈现。
A simple way to make this error occur: 发生此错误的简单方法:
<div>{{functionThatReturnsDifferentValueOnEveryCall()}}</div>
...
count = 0;
functionThatReturnsDifferentValueOnEveryCall() {
return count++;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.