解决方法
使用(window:resize)=“onResize($event)”来监听全局事件.您可以使用窗口,文档或身体作为目标.见
this plunk
@Component({ selector: 'my-app',template: ` <div class="square" [style.width.px]="width" [style.height.px]="height" (window:resize)="onResize($event)" ></div> ` }) export class App { width = 100; height = 100; onResize(event) { this.width += 100; this.height += 100; } }