我使用Angular Material Portal将元素移动到另一个位置。
我不明白为什么在这个超级简单的示例中角度抛出表达式会发生变化
import { Component,ViewChild } from '@angular/core';
import { cdkPortal } from '@angular/cdk/portal';
@Component({
selector: 'my-app',templateUrl: './app.component.html',styleUrls: [ './app.component.css' ]
})
export class AppComponent {
name = 'Angular';
@ViewChild(cdkPortal,{ static: false }) portal: cdkPortal
}
在此处检查代码: https://stackblitz.com/edit/angular-f6sb21
打开控制台以查看错误:
ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'portal: undefined'. Current value: 'portal: [object Object]'