是否可以使用* ngIf在任何条件下重新渲染组件?我认为我可以进行超时,大约200ms,然后将组件值赋值为null,更新组件值并重新发送 . 但是可以在没有超时的情况下重新渲染并更改组件的值吗?
例:
@Component({})
export class RepComponent implements OnInit {
component: any;
constructor() {}
ngOnInit() {
this.component = this.route.snapshot.data['component'];
}
}
<div *ngIf="component.type === 'Text'">
<!-- ... -->
</div>
<div *ngIf="component.type === 'Image'">
<!-- ... -->
</div>
所以由于例子,我需要如果 component.type
是'Image',组件本身会重新渲染新数据 .
1 回答
也许你应该在ngOnInit的html中使用相同的变量?
希望这有帮助